[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" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 34 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 35 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 36 | #include "net/base/load_timing_info.h" |
| 37 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 38 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 40 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 41 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 42 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 43 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 44 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 45 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 46 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 47 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 48 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 49 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 50 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 54 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 55 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 57 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 58 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 59 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 60 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 61 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 62 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 70 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 71 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 72 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 73 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 74 | #include "net/proxy_resolution/proxy_resolver.h" |
| 75 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 79 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 80 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 82 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 83 | #include "net/socket/socket_test_util.h" |
| 84 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 85 | #include "net/spdy/spdy_session.h" |
| 86 | #include "net/spdy/spdy_session_pool.h" |
| 87 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 88 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 89 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 90 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 92 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 93 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 94 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 95 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 96 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 2e003eea | 2018-05-02 00:24:29 | [diff] [blame] | 97 | #include "net/third_party/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 98 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 99 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 100 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 101 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 102 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 103 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 104 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 106 | #if defined(NTLM_PORTABLE) |
| 107 | #include "base/base64.h" |
| 108 | #include "net/ntlm/ntlm_test_data.h" |
| 109 | #endif |
| 110 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 111 | using net::test::IsError; |
| 112 | using net::test::IsOk; |
| 113 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 114 | using base::ASCIIToUTF16; |
| 115 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 116 | //----------------------------------------------------------------------------- |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | namespace net { |
| 119 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 120 | namespace { |
| 121 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 122 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 123 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 124 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 125 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 126 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 127 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 128 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 129 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 130 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 131 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 132 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 133 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 134 | const char kAlternativeServiceHttpHeader[] = |
| 135 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 136 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 137 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 138 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 139 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 140 | } |
| 141 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 142 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 143 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 144 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 145 | } |
| 146 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 147 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 148 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 149 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 152 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 153 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 154 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 155 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 156 | if (!params) |
| 157 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 158 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 159 | if (!params->GetList("headers", &header_list)) |
| 160 | return false; |
| 161 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 162 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 163 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 164 | return true; |
| 165 | } |
| 166 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 167 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 168 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 169 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 170 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 171 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 172 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 173 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 174 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 175 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 176 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 177 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 178 | |
| 179 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 180 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 181 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 183 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 184 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 185 | } |
| 186 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 187 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 188 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 189 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 192 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 193 | |
| 194 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 196 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 197 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 198 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 200 | load_timing_info.send_start); |
| 201 | |
| 202 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 204 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 206 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 207 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 211 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 212 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 213 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 214 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 216 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | |
| 218 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 219 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 220 | load_timing_info.proxy_resolve_end); |
| 221 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 222 | load_timing_info.send_start); |
| 223 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 224 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 225 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 227 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 228 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 232 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 233 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 234 | int connect_timing_flags) { |
| 235 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 236 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | |
| 238 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 239 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 240 | load_timing_info.proxy_resolve_end); |
| 241 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 242 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 243 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 244 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 245 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 246 | load_timing_info.send_start); |
| 247 | |
| 248 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 250 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 251 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 252 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 253 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 254 | } |
| 255 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 256 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 257 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 258 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 259 | } |
| 260 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 261 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 262 | public: |
| 263 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 264 | |
| 265 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 266 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 267 | std::unique_ptr<ProxyResolver>* result, |
| 268 | const CompletionCallback& callback, |
| 269 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 270 | return ERR_PAC_SCRIPT_FAILED; |
| 271 | } |
| 272 | }; |
| 273 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 274 | class TestSSLConfigService : public SSLConfigService { |
| 275 | public: |
| 276 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
| 277 | |
| 278 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 279 | |
| 280 | private: |
| 281 | ~TestSSLConfigService() override = default; |
| 282 | |
| 283 | SSLConfig config_; |
| 284 | }; |
| 285 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 286 | } // namespace |
| 287 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 288 | class HttpNetworkTransactionTest : public PlatformTest, |
| 289 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 290 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 291 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 292 | // Important to restore the per-pool limit first, since the pool limit must |
| 293 | // always be greater than group limit, and the tests reduce both limits. |
| 294 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 295 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 296 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 297 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 298 | } |
| 299 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 300 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 301 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 302 | : ssl_(ASYNC, OK), |
| 303 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 304 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 305 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 306 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 307 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 308 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 309 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 310 | struct SimpleGetHelperResult { |
| 311 | int rv; |
| 312 | std::string status_line; |
| 313 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 314 | int64_t total_received_bytes; |
| 315 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 316 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 317 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 318 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 319 | }; |
| 320 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 321 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 322 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 323 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 324 | } |
| 325 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 326 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 327 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 328 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 329 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 330 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 331 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 332 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 333 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 336 | // Either |write_failure| specifies a write failure or |read_failure| |
| 337 | // specifies a read failure when using a reused socket. In either case, the |
| 338 | // failure should cause the network transaction to resend the request, and the |
| 339 | // other argument should be NULL. |
| 340 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 341 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 342 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 343 | // Either |write_failure| specifies a write failure or |read_failure| |
| 344 | // specifies a read failure when using a reused socket. In either case, the |
| 345 | // failure should cause the network transaction to resend the request, and the |
| 346 | // other argument should be NULL. |
| 347 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 348 | const MockRead* read_failure, |
| 349 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 351 | SimpleGetHelperResult SimpleGetHelperForData( |
| 352 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 354 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 355 | HttpRequestInfo request; |
| 356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 357 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 358 | request.traffic_annotation = |
| 359 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 360 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 361 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 362 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 363 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 365 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 366 | for (auto* provider : providers) { |
| 367 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 368 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 370 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 371 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 372 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 373 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 375 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 376 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 377 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 378 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 379 | |
| 380 | // Even in the failure cases that use this function, connections are always |
| 381 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 382 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 383 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 384 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 385 | if (out.rv != OK) |
| 386 | return out; |
| 387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 388 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 389 | // Can't use ASSERT_* inside helper functions like this, so |
| 390 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 391 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 392 | out.rv = ERR_UNEXPECTED; |
| 393 | return out; |
| 394 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 395 | out.status_line = response->headers->GetStatusLine(); |
| 396 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 397 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 398 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 399 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 400 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 401 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 402 | EXPECT_EQ(got_endpoint, |
| 403 | out.remote_endpoint_after_start.address().size() > 0); |
| 404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 405 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 408 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 409 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 410 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 411 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 412 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 413 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 414 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 415 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 416 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 417 | std::string line; |
| 418 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 419 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 420 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 421 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 422 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 423 | std::string value; |
| 424 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 425 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 426 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 427 | EXPECT_EQ("keep-alive", value); |
| 428 | |
| 429 | std::string response_headers; |
| 430 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 431 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 432 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 434 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 435 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 436 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 438 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 439 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 440 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 442 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 443 | MockWrite data_writes[] = { |
| 444 | MockWrite("GET / HTTP/1.1\r\n" |
| 445 | "Host: www.example.org\r\n" |
| 446 | "Connection: keep-alive\r\n\r\n"), |
| 447 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 448 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 449 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 450 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 451 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 453 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 454 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 455 | } |
| 456 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 457 | void AddSSLSocketData() { |
| 458 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 459 | ssl_.ssl_info.cert = |
| 460 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 461 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 463 | } |
| 464 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 465 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 466 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 467 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 468 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 469 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 470 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 471 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 472 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 473 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 474 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 475 | |
| 476 | // Original socket limits. Some tests set these. Safest to always restore |
| 477 | // them once each test has been run. |
| 478 | int old_max_group_sockets_; |
| 479 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 480 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 481 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 482 | namespace { |
| 483 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 484 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 485 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 486 | BeforeHeadersSentHandler() |
| 487 | : observed_before_headers_sent_with_proxy_(false), |
| 488 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 489 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 490 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 491 | HttpRequestHeaders* request_headers) { |
| 492 | observed_before_headers_sent_ = true; |
| 493 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 494 | !proxy_info.is_quic()) { |
| 495 | return; |
| 496 | } |
| 497 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 498 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 499 | } |
| 500 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 501 | bool observed_before_headers_sent_with_proxy() const { |
| 502 | return observed_before_headers_sent_with_proxy_; |
| 503 | } |
| 504 | |
| 505 | bool observed_before_headers_sent() const { |
| 506 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | std::string observed_proxy_server_uri() const { |
| 510 | return observed_proxy_server_uri_; |
| 511 | } |
| 512 | |
| 513 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 514 | bool observed_before_headers_sent_with_proxy_; |
| 515 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 516 | std::string observed_proxy_server_uri_; |
| 517 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 518 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 519 | }; |
| 520 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 521 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 522 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 523 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 524 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 525 | const int sizeof_row = strlen(row); |
| 526 | const int num_rows = static_cast<int>( |
| 527 | ceil(static_cast<float>(size) / sizeof_row)); |
| 528 | const int sizeof_data = num_rows * sizeof_row; |
| 529 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 530 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 531 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 532 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 533 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 534 | } |
| 535 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 536 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 537 | uint64_t MockGetMSTime() { |
| 538 | // Tue, 23 May 2017 20:13:07 +0000 |
| 539 | return 131400439870000000; |
| 540 | } |
| 541 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 542 | // Alternative functions that eliminate randomness and dependency on the local |
| 543 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 544 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 545 | // This is set to 0xaa because the client challenge for testing in |
| 546 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 547 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 548 | } |
| 549 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 550 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 551 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 552 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 553 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 554 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 555 | template<typename ParentPool> |
| 556 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 557 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 558 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 559 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 560 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 561 | const std::string last_group_name_received() const { |
| 562 | return last_group_name_; |
| 563 | } |
| 564 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 565 | bool socket_requested() const { return socket_requested_; } |
| 566 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 567 | int RequestSocket(const std::string& group_name, |
| 568 | const void* socket_params, |
| 569 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 570 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 571 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 572 | ClientSocketHandle* handle, |
| 573 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 574 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 575 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 576 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 577 | return ERR_IO_PENDING; |
| 578 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 579 | void CancelRequest(const std::string& group_name, |
| 580 | ClientSocketHandle* handle) override {} |
| 581 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 582 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 583 | int id) override {} |
| 584 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 585 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 586 | int IdleSocketCount() const override { return 0; } |
| 587 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 588 | return 0; |
| 589 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 590 | LoadState GetLoadState(const std::string& group_name, |
| 591 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 592 | return LOAD_STATE_IDLE; |
| 593 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 594 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 595 | return base::TimeDelta(); |
| 596 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 597 | |
| 598 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 599 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 600 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 601 | }; |
| 602 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 603 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 604 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 605 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 606 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 607 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 608 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 609 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 610 | CaptureGroupNameSSLSocketPool; |
| 611 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 612 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 613 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 614 | HostResolver* host_resolver, |
| 615 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 616 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 617 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 618 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 619 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 620 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 621 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 622 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 623 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 624 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 625 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 626 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 627 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 628 | : SSLClientSocketPool(0, |
| 629 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 630 | cert_verifier, |
| 631 | NULL, |
| 632 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 633 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 634 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 635 | std::string(), |
| 636 | NULL, |
| 637 | NULL, |
| 638 | NULL, |
| 639 | NULL, |
| 640 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 641 | NULL) { |
| 642 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 643 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 644 | //----------------------------------------------------------------------------- |
| 645 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 646 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 647 | // configured for common cases. |
| 648 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 649 | if (!auth_challenge) |
| 650 | return false; |
| 651 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 652 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 653 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 654 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 655 | return true; |
| 656 | } |
| 657 | |
| 658 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 659 | if (!auth_challenge) |
| 660 | return false; |
| 661 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 662 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 663 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 664 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 665 | return true; |
| 666 | } |
| 667 | |
| 668 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 669 | if (!auth_challenge) |
| 670 | return false; |
| 671 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 672 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 673 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 674 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 675 | return true; |
| 676 | } |
| 677 | |
| 678 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 679 | if (!auth_challenge) |
| 680 | return false; |
| 681 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 682 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 683 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 684 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 685 | return true; |
| 686 | } |
| 687 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 688 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 689 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 690 | if (!auth_challenge) |
| 691 | return false; |
| 692 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 693 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 694 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 695 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 696 | return true; |
| 697 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 698 | |
| 699 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 700 | if (!auth_challenge) |
| 701 | return false; |
| 702 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 703 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 704 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 705 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 706 | return true; |
| 707 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 708 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 709 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 710 | } // namespace |
| 711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 712 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 715 | } |
| 716 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 717 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 719 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 720 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 721 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 722 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 723 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 724 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 726 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 727 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 728 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 729 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 730 | |
| 731 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 735 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 736 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 737 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 738 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 739 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 740 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 741 | EXPECT_THAT(out.rv, IsOk()); |
| 742 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 743 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 744 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 745 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 746 | } |
| 747 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 748 | // Response with no status line, and a weird port. Should fail by default. |
| 749 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 750 | MockRead data_reads[] = { |
| 751 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 752 | }; |
| 753 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 754 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 756 | |
| 757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 758 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 759 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 760 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 761 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 762 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 763 | request.method = "GET"; |
| 764 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 765 | request.traffic_annotation = |
| 766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 767 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 768 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 769 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 770 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 771 | } |
| 772 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 773 | // Tests that request info can be destroyed after the headers phase is complete. |
| 774 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 776 | auto trans = |
| 777 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 778 | |
| 779 | MockRead data_reads[] = { |
| 780 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 781 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 782 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 783 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 785 | |
| 786 | TestCompletionCallback callback; |
| 787 | |
| 788 | { |
| 789 | auto request = std::make_unique<HttpRequestInfo>(); |
| 790 | request->method = "GET"; |
| 791 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 792 | request->traffic_annotation = |
| 793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 794 | |
| 795 | int rv = |
| 796 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 797 | |
| 798 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 799 | } // Let request info be destroyed. |
| 800 | |
| 801 | trans.reset(); |
| 802 | } |
| 803 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 804 | // Response with no status line, and a weird port. Option to allow weird ports |
| 805 | // enabled. |
| 806 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 807 | MockRead data_reads[] = { |
| 808 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 809 | }; |
| 810 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 811 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 812 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 813 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 815 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 816 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 817 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 818 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 819 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 820 | request.method = "GET"; |
| 821 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 822 | request.traffic_annotation = |
| 823 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 824 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 825 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 826 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 827 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 828 | |
| 829 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 830 | ASSERT_TRUE(info->headers); |
| 831 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 832 | |
| 833 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 834 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 835 | } |
| 836 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 837 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 838 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 839 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 840 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 841 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 843 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 844 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 845 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 846 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 847 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 848 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 852 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 853 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 854 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 855 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 856 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 857 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 858 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 859 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 860 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 861 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 862 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 866 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 867 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 868 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 869 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 870 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 871 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 872 | EXPECT_THAT(out.rv, IsOk()); |
| 873 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 874 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 875 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 876 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 880 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 881 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 882 | MockRead("\n"), |
| 883 | MockRead("\n"), |
| 884 | MockRead("Q"), |
| 885 | MockRead("J"), |
| 886 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 887 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 888 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 889 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 890 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 891 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 892 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 893 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 894 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 898 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 899 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 900 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 901 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 902 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 903 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 904 | EXPECT_THAT(out.rv, IsOk()); |
| 905 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 906 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 907 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 908 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 909 | } |
| 910 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 911 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 912 | // persistent connection. The response should still terminate since a 204 |
| 913 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 914 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 915 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 916 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 917 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 918 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 919 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 920 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 921 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 922 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 923 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 924 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 925 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 926 | int64_t response_size = reads_size - strlen(junk); |
| 927 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 928 | } |
| 929 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 930 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 931 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 932 | std::string final_chunk = "0\r\n\r\n"; |
| 933 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 934 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 935 | MockRead data_reads[] = { |
| 936 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 937 | MockRead("5\r\nHello\r\n"), |
| 938 | MockRead("1\r\n"), |
| 939 | MockRead(" \r\n"), |
| 940 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 941 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 942 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 943 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 944 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 945 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 946 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 947 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 948 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 949 | int64_t response_size = reads_size - extra_data.size(); |
| 950 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 951 | } |
| 952 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 953 | // Next tests deal with http://crbug.com/56344. |
| 954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 955 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 956 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 957 | MockRead data_reads[] = { |
| 958 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 959 | MockRead("Content-Length: 10\r\n"), |
| 960 | MockRead("Content-Length: 5\r\n\r\n"), |
| 961 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 963 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 964 | } |
| 965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 966 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 967 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 968 | MockRead data_reads[] = { |
| 969 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 970 | MockRead("Content-Length: 5\r\n"), |
| 971 | MockRead("Content-Length: 5\r\n\r\n"), |
| 972 | MockRead("Hello"), |
| 973 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 974 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 975 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 976 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 977 | EXPECT_EQ("Hello", out.response_data); |
| 978 | } |
| 979 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 980 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 981 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 982 | // More than 2 dupes. |
| 983 | { |
| 984 | MockRead data_reads[] = { |
| 985 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 986 | MockRead("Content-Length: 5\r\n"), |
| 987 | MockRead("Content-Length: 5\r\n"), |
| 988 | MockRead("Content-Length: 5\r\n\r\n"), |
| 989 | MockRead("Hello"), |
| 990 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 991 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 992 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 993 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 994 | EXPECT_EQ("Hello", out.response_data); |
| 995 | } |
| 996 | // HTTP/1.0 |
| 997 | { |
| 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1000 | MockRead("Content-Length: 5\r\n"), |
| 1001 | MockRead("Content-Length: 5\r\n"), |
| 1002 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1003 | MockRead("Hello"), |
| 1004 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1005 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1006 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1007 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1008 | EXPECT_EQ("Hello", out.response_data); |
| 1009 | } |
| 1010 | // 2 dupes and one mismatched. |
| 1011 | { |
| 1012 | MockRead data_reads[] = { |
| 1013 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1014 | MockRead("Content-Length: 10\r\n"), |
| 1015 | MockRead("Content-Length: 10\r\n"), |
| 1016 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1017 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1018 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1019 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1020 | } |
| 1021 | } |
| 1022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1023 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1024 | MultipleContentLengthHeadersTransferEncoding) { |
| 1025 | MockRead data_reads[] = { |
| 1026 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1027 | MockRead("Content-Length: 666\r\n"), |
| 1028 | MockRead("Content-Length: 1337\r\n"), |
| 1029 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1030 | MockRead("5\r\nHello\r\n"), |
| 1031 | MockRead("1\r\n"), |
| 1032 | MockRead(" \r\n"), |
| 1033 | MockRead("5\r\nworld\r\n"), |
| 1034 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1035 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1036 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1037 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1038 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1039 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1040 | EXPECT_EQ("Hello world", out.response_data); |
| 1041 | } |
| 1042 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1043 | // Next tests deal with http://crbug.com/98895. |
| 1044 | |
| 1045 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1046 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1047 | MockRead data_reads[] = { |
| 1048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1049 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1051 | MockRead("Hello"), |
| 1052 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1053 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1054 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1055 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1056 | EXPECT_EQ("Hello", out.response_data); |
| 1057 | } |
| 1058 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1059 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1060 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1061 | MockRead data_reads[] = { |
| 1062 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1063 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1064 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1066 | MockRead("Hello"), |
| 1067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1068 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1069 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1070 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1071 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1075 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1076 | MockRead data_reads[] = { |
| 1077 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1078 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1079 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1081 | MockRead("Hello"), |
| 1082 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1083 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1084 | EXPECT_THAT(out.rv, |
| 1085 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1086 | } |
| 1087 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1088 | // Checks that two identical Location headers result in no error. |
| 1089 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1090 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1091 | MockRead data_reads[] = { |
| 1092 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1093 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1094 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1095 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1096 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1097 | }; |
| 1098 | |
| 1099 | HttpRequestInfo request; |
| 1100 | request.method = "GET"; |
| 1101 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1102 | request.traffic_annotation = |
| 1103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1106 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1107 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1108 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1111 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1113 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1115 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1116 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1118 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1119 | ASSERT_TRUE(response); |
| 1120 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1121 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1122 | std::string url; |
| 1123 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1124 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1125 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | } |
| 1127 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1128 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1129 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1130 | MockRead data_reads[] = { |
| 1131 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1132 | MockRead("Location: http://good.com/\r\n"), |
| 1133 | MockRead("Location: http://evil.com/\r\n"), |
| 1134 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1135 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1136 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1137 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1138 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | } |
| 1140 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1141 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1142 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1143 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1144 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1145 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1146 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1147 | request.traffic_annotation = |
| 1148 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1152 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1153 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1154 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1155 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1156 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1157 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1158 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1159 | "Host: www.example.org\r\n" |
| 1160 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1161 | }; |
| 1162 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1163 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1164 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1165 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1166 | // No response body because the test stops reading here. |
| 1167 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1168 | }; |
| 1169 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1170 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1173 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1174 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1175 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1177 | |
| 1178 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1181 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1182 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1183 | |
| 1184 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1185 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1186 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1187 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1188 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1189 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1190 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1191 | |
| 1192 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1193 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1194 | bool has_server_header = response->headers->EnumerateHeader( |
| 1195 | &iter, "Server", &server_header); |
| 1196 | EXPECT_TRUE(has_server_header); |
| 1197 | EXPECT_EQ("Blah", server_header); |
| 1198 | |
| 1199 | // Reading should give EOF right away, since there is no message body |
| 1200 | // (despite non-zero content-length). |
| 1201 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1202 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1204 | EXPECT_EQ("", response_data); |
| 1205 | } |
| 1206 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1207 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1208 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1209 | |
| 1210 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1211 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1212 | MockRead("hello"), |
| 1213 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1214 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1215 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1216 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1217 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1219 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1220 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1221 | "hello", "world" |
| 1222 | }; |
| 1223 | |
| 1224 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1225 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1226 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1227 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1228 | request.traffic_annotation = |
| 1229 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1233 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1234 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1235 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1237 | |
| 1238 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1239 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1241 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1242 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1243 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1244 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1245 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1246 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1247 | |
| 1248 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1249 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1251 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1252 | } |
| 1253 | } |
| 1254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1255 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1256 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1257 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1258 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1259 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1260 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1261 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1262 | request.method = "POST"; |
| 1263 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1264 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1265 | request.traffic_annotation = |
| 1266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1267 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1268 | // Check the upload progress returned before initialization is correct. |
| 1269 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1270 | EXPECT_EQ(0u, progress.size()); |
| 1271 | EXPECT_EQ(0u, progress.position()); |
| 1272 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1273 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1275 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1276 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1277 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1278 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1279 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1280 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1281 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1282 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1283 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1285 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1287 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
| 1290 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1291 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1293 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1294 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1296 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1297 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | |
| 1299 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1300 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1302 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | } |
| 1304 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1305 | // This test is almost the same as Ignores100 above, but the response contains |
| 1306 | // 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] | 1307 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1308 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1309 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1310 | request.method = "GET"; |
| 1311 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1312 | request.traffic_annotation = |
| 1313 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1314 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1316 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1317 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1318 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1319 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1320 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1321 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1322 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1323 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1324 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1325 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1326 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1327 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1328 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1329 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1331 | |
| 1332 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1333 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1334 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1335 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1336 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1337 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1338 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1339 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1340 | |
| 1341 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1342 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1343 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1344 | EXPECT_EQ("hello world", response_data); |
| 1345 | } |
| 1346 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1347 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1348 | HttpRequestInfo request; |
| 1349 | request.method = "POST"; |
| 1350 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1351 | request.traffic_annotation = |
| 1352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1355 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1356 | |
| 1357 | MockRead data_reads[] = { |
| 1358 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1359 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1360 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1361 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1363 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1364 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1366 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1368 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1369 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1371 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1372 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1373 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1374 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1375 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1376 | } |
| 1377 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1378 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1379 | HttpRequestInfo request; |
| 1380 | request.method = "POST"; |
| 1381 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1382 | request.traffic_annotation = |
| 1383 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1386 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1387 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1388 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1389 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1390 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1391 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1392 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1394 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1398 | |
| 1399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1400 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1401 | } |
| 1402 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1403 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1404 | const MockWrite* write_failure, |
| 1405 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1406 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1407 | request.method = "GET"; |
| 1408 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1409 | request.traffic_annotation = |
| 1410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1411 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1412 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1413 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1414 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1415 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1416 | // Written data for successfully sending both requests. |
| 1417 | MockWrite data1_writes[] = { |
| 1418 | MockWrite("GET / HTTP/1.1\r\n" |
| 1419 | "Host: www.foo.com\r\n" |
| 1420 | "Connection: keep-alive\r\n\r\n"), |
| 1421 | MockWrite("GET / HTTP/1.1\r\n" |
| 1422 | "Host: www.foo.com\r\n" |
| 1423 | "Connection: keep-alive\r\n\r\n") |
| 1424 | }; |
| 1425 | |
| 1426 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1427 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1428 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1429 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1430 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1431 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1432 | |
| 1433 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1434 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1435 | data1_writes[1] = *write_failure; |
| 1436 | } else { |
| 1437 | ASSERT_TRUE(read_failure); |
| 1438 | data1_reads[2] = *read_failure; |
| 1439 | } |
| 1440 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1441 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1442 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1443 | |
| 1444 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1445 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1446 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1447 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1448 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1449 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1450 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1451 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1452 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1453 | "hello", "world" |
| 1454 | }; |
| 1455 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1456 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1457 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1458 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1464 | |
| 1465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1466 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1467 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1468 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1469 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1470 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1471 | if (i == 0) { |
| 1472 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1473 | } else { |
| 1474 | // The second request should be using a new socket. |
| 1475 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1476 | } |
| 1477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1479 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1481 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1482 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1483 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1484 | |
| 1485 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1486 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1487 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1488 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1489 | } |
| 1490 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1491 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1492 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1493 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1494 | const MockRead* read_failure, |
| 1495 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1496 | HttpRequestInfo request; |
| 1497 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1498 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1499 | request.traffic_annotation = |
| 1500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1501 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1502 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1503 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1505 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1506 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1507 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1508 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1509 | ssl1.next_proto = kProtoHTTP2; |
| 1510 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1511 | } |
| 1512 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1514 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1515 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1516 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1517 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1518 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1519 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1520 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1521 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1522 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1523 | // HTTP/1.1 versions of the request and response. |
| 1524 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1525 | "Host: www.foo.com\r\n" |
| 1526 | "Connection: keep-alive\r\n\r\n"; |
| 1527 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1528 | const char kHttpData[] = "hello"; |
| 1529 | |
| 1530 | std::vector<MockRead> data1_reads; |
| 1531 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1532 | if (write_failure) { |
| 1533 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1534 | data1_writes.push_back(*write_failure); |
| 1535 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1536 | } else { |
| 1537 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1538 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1539 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1540 | } else { |
| 1541 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1542 | } |
| 1543 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1544 | } |
| 1545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1546 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1547 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1548 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1549 | std::vector<MockRead> data2_reads; |
| 1550 | std::vector<MockWrite> data2_writes; |
| 1551 | |
| 1552 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1553 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1554 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1555 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1556 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1557 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1558 | } else { |
| 1559 | data2_writes.push_back( |
| 1560 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1561 | |
| 1562 | data2_reads.push_back( |
| 1563 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1564 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1565 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1566 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1567 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1568 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1569 | |
| 1570 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1571 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1572 | // Wait for the preconnect to complete. |
| 1573 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1574 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1575 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1576 | |
| 1577 | // Make the request. |
| 1578 | TestCompletionCallback callback; |
| 1579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1580 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1582 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1584 | |
| 1585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1586 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | |
| 1588 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1589 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1590 | TestLoadTimingNotReused( |
| 1591 | load_timing_info, |
| 1592 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1595 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1596 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1597 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1598 | if (response->was_fetched_via_spdy) { |
| 1599 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1600 | } else { |
| 1601 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1602 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1603 | |
| 1604 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1605 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1607 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1608 | } |
| 1609 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1610 | // Test that we do not retry indefinitely when a server sends an error like |
| 1611 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1612 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1613 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1614 | HttpRequestInfo request; |
| 1615 | request.method = "GET"; |
| 1616 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1617 | request.traffic_annotation = |
| 1618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1619 | |
| 1620 | // Check whether we give up after the third try. |
| 1621 | |
| 1622 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1623 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1624 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1625 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1626 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1627 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1628 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1629 | |
| 1630 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1631 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1632 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1633 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1634 | |
| 1635 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1636 | AddSSLSocketData(); |
| 1637 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1638 | AddSSLSocketData(); |
| 1639 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1640 | AddSSLSocketData(); |
| 1641 | |
| 1642 | TestCompletionCallback callback; |
| 1643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1645 | |
| 1646 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1648 | |
| 1649 | rv = callback.WaitForResult(); |
| 1650 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1651 | } |
| 1652 | |
| 1653 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1654 | HttpRequestInfo request; |
| 1655 | request.method = "GET"; |
| 1656 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1657 | request.traffic_annotation = |
| 1658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1659 | |
| 1660 | // Check whether we try atleast thrice before giving up. |
| 1661 | |
| 1662 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1663 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1664 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1665 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1666 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1667 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1668 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1669 | |
| 1670 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1671 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1672 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 1673 | spdy::SpdySerializedFrame spdy_data( |
| 1674 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1675 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1676 | CreateMockRead(spdy_data, 2)}; |
| 1677 | |
| 1678 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1679 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1680 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1681 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1682 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1683 | |
| 1684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1685 | AddSSLSocketData(); |
| 1686 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1687 | AddSSLSocketData(); |
| 1688 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1689 | AddSSLSocketData(); |
| 1690 | |
| 1691 | TestCompletionCallback callback; |
| 1692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1694 | |
| 1695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1697 | |
| 1698 | rv = callback.WaitForResult(); |
| 1699 | EXPECT_THAT(rv, IsOk()); |
| 1700 | } |
| 1701 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1702 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1703 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1704 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1705 | } |
| 1706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1707 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1708 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1709 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1710 | } |
| 1711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1712 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1713 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1714 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1715 | } |
| 1716 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1717 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1718 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1719 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1720 | MockRead read_failure(SYNCHRONOUS, |
| 1721 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1722 | "Connection: Keep-Alive\r\n" |
| 1723 | "Content-Length: 6\r\n\r\n" |
| 1724 | "Pickle"); |
| 1725 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1726 | } |
| 1727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1728 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1729 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1730 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1731 | } |
| 1732 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1733 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1734 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1735 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1736 | } |
| 1737 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1738 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1739 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1740 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1741 | } |
| 1742 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1743 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1744 | MockRead read_failure(ASYNC, OK); // EOF |
| 1745 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1746 | } |
| 1747 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1748 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1749 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1750 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1751 | MockRead read_failure(SYNCHRONOUS, |
| 1752 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1753 | "Connection: Keep-Alive\r\n" |
| 1754 | "Content-Length: 6\r\n\r\n" |
| 1755 | "Pickle"); |
| 1756 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1757 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1758 | } |
| 1759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1760 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1761 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1762 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1763 | } |
| 1764 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1765 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1766 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1767 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1768 | } |
| 1769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1770 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1771 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1772 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1773 | } |
| 1774 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1775 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1776 | MockRead read_failure(ASYNC, OK); // EOF |
| 1777 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1778 | } |
| 1779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1780 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1781 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1782 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1783 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1784 | request.traffic_annotation = |
| 1785 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1786 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1787 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1788 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1789 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1790 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1791 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1792 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1793 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1795 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1796 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1799 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1803 | |
| 1804 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1805 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1806 | |
| 1807 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1808 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1809 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | // What do various browsers do when the server closes a non-keepalive |
| 1813 | // connection without sending any response header or body? |
| 1814 | // |
| 1815 | // IE7: error page |
| 1816 | // Safari 3.1.2 (Windows): error page |
| 1817 | // Firefox 3.0.1: blank page |
| 1818 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1819 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1820 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1821 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1822 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1823 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1824 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1825 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1826 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1827 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1828 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1829 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1830 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1831 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1832 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1833 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1834 | // destructor in such situations. |
| 1835 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1836 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1837 | HttpRequestInfo request; |
| 1838 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1839 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1840 | request.traffic_annotation = |
| 1841 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1842 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1844 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1845 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1846 | |
| 1847 | MockRead data_reads[] = { |
| 1848 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1849 | MockRead("Connection: keep-alive\r\n"), |
| 1850 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1851 | MockRead("hello"), |
| 1852 | MockRead(SYNCHRONOUS, 0), |
| 1853 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1854 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1856 | |
| 1857 | TestCompletionCallback callback; |
| 1858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1859 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1861 | |
| 1862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | |
| 1865 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1866 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1867 | if (rv == ERR_IO_PENDING) |
| 1868 | rv = callback.WaitForResult(); |
| 1869 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1870 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1871 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1872 | |
| 1873 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1874 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1875 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1876 | } |
| 1877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1878 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1879 | HttpRequestInfo request; |
| 1880 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1881 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1882 | request.traffic_annotation = |
| 1883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1884 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1885 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1886 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1887 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1888 | |
| 1889 | MockRead data_reads[] = { |
| 1890 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1891 | MockRead("Connection: keep-alive\r\n"), |
| 1892 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1893 | MockRead(SYNCHRONOUS, 0), |
| 1894 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1895 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1897 | |
| 1898 | TestCompletionCallback callback; |
| 1899 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1900 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1902 | |
| 1903 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1904 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1905 | |
| 1906 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1907 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1908 | if (rv == ERR_IO_PENDING) |
| 1909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1910 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1911 | |
| 1912 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1913 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1914 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1915 | } |
| 1916 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1917 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1918 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1919 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1920 | HttpRequestInfo request; |
| 1921 | request.method = "GET"; |
| 1922 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1923 | request.traffic_annotation = |
| 1924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1925 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1926 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1927 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1929 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1930 | const char* request_data = |
| 1931 | "GET / HTTP/1.1\r\n" |
| 1932 | "Host: www.foo.com\r\n" |
| 1933 | "Connection: keep-alive\r\n\r\n"; |
| 1934 | MockWrite data_writes[] = { |
| 1935 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1936 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1937 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1938 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1939 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1940 | }; |
| 1941 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1942 | // Note that because all these reads happen in the same |
| 1943 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1944 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1945 | MockRead data_reads[] = { |
| 1946 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1947 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1948 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1949 | MockRead(ASYNC, 7, |
| 1950 | "HTTP/1.1 302 Found\r\n" |
| 1951 | "Content-Length: 0\r\n\r\n"), |
| 1952 | MockRead(ASYNC, 9, |
| 1953 | "HTTP/1.1 302 Found\r\n" |
| 1954 | "Content-Length: 5\r\n\r\n" |
| 1955 | "hello"), |
| 1956 | MockRead(ASYNC, 11, |
| 1957 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1958 | "Content-Length: 0\r\n\r\n"), |
| 1959 | MockRead(ASYNC, 13, |
| 1960 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1961 | "Content-Length: 5\r\n\r\n" |
| 1962 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1963 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1964 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1965 | // the set_busy_before_sync_reads(true) call, while the |
| 1966 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1967 | // reuseable. See http://crbug.com/544255. |
| 1968 | MockRead(ASYNC, 15, |
| 1969 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1970 | "Content-Length: 5\r\n\r\n"), |
| 1971 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1972 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1973 | MockRead(ASYNC, 18, |
| 1974 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1975 | "Content-Length: 5\r\n\r\n" |
| 1976 | "he"), |
| 1977 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1978 | |
| 1979 | // The body of the final request is actually read. |
| 1980 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1981 | MockRead(ASYNC, 22, "hello"), |
| 1982 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1983 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1984 | data.set_busy_before_sync_reads(true); |
| 1985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1986 | |
| 1987 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1988 | std::string response_lines[kNumUnreadBodies]; |
| 1989 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1990 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1991 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1992 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1993 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1994 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1995 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1997 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1998 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1999 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2000 | LoadTimingInfo load_timing_info; |
| 2001 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2002 | if (i == 0) { |
| 2003 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2004 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2005 | } else { |
| 2006 | TestLoadTimingReused(load_timing_info); |
| 2007 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2008 | } |
| 2009 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2011 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2012 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2013 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2014 | response_lines[i] = response->headers->GetStatusLine(); |
| 2015 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2016 | // Delete the transaction without reading the response bodies. Then spin |
| 2017 | // the message loop, so the response bodies are drained. |
| 2018 | trans.reset(); |
| 2019 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2020 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2021 | |
| 2022 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2023 | "HTTP/1.1 204 No Content", |
| 2024 | "HTTP/1.1 205 Reset Content", |
| 2025 | "HTTP/1.1 304 Not Modified", |
| 2026 | "HTTP/1.1 302 Found", |
| 2027 | "HTTP/1.1 302 Found", |
| 2028 | "HTTP/1.1 301 Moved Permanently", |
| 2029 | "HTTP/1.1 301 Moved Permanently", |
| 2030 | "HTTP/1.1 200 Hunky-Dory", |
| 2031 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2032 | }; |
| 2033 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2034 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2035 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2036 | |
| 2037 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2038 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2040 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2041 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2042 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2043 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2044 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2045 | ASSERT_TRUE(response); |
| 2046 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2047 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2048 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2049 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2050 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2051 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2052 | } |
| 2053 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2054 | // Sockets that receive extra data after a response is complete should not be |
| 2055 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2056 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2057 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2058 | MockWrite data_writes1[] = { |
| 2059 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2060 | "Host: www.borked.com\r\n" |
| 2061 | "Connection: keep-alive\r\n\r\n"), |
| 2062 | }; |
| 2063 | |
| 2064 | MockRead data_reads1[] = { |
| 2065 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2066 | "Connection: keep-alive\r\n" |
| 2067 | "Content-Length: 22\r\n\r\n" |
| 2068 | "This server is borked."), |
| 2069 | }; |
| 2070 | |
| 2071 | MockWrite data_writes2[] = { |
| 2072 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2073 | "Host: www.borked.com\r\n" |
| 2074 | "Connection: keep-alive\r\n\r\n"), |
| 2075 | }; |
| 2076 | |
| 2077 | MockRead data_reads2[] = { |
| 2078 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2079 | "Content-Length: 3\r\n\r\n" |
| 2080 | "foo"), |
| 2081 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2082 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2084 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2085 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2086 | |
| 2087 | TestCompletionCallback callback; |
| 2088 | HttpRequestInfo request1; |
| 2089 | request1.method = "HEAD"; |
| 2090 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2091 | request1.traffic_annotation = |
| 2092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2093 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2094 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2095 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2096 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2097 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2098 | |
| 2099 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2100 | ASSERT_TRUE(response1); |
| 2101 | ASSERT_TRUE(response1->headers); |
| 2102 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2103 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2104 | |
| 2105 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2106 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2107 | EXPECT_EQ("", response_data1); |
| 2108 | // Deleting the transaction attempts to release the socket back into the |
| 2109 | // socket pool. |
| 2110 | trans1.reset(); |
| 2111 | |
| 2112 | HttpRequestInfo request2; |
| 2113 | request2.method = "GET"; |
| 2114 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2115 | request2.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 trans2 = |
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 | rv = trans2->Start(&request2, 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* response2 = trans2->GetResponseInfo(); |
| 2124 | ASSERT_TRUE(response2); |
| 2125 | ASSERT_TRUE(response2->headers); |
| 2126 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2127 | |
| 2128 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2129 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2130 | EXPECT_EQ("foo", response_data2); |
| 2131 | } |
| 2132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2133 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2135 | MockWrite data_writes1[] = { |
| 2136 | MockWrite("GET / HTTP/1.1\r\n" |
| 2137 | "Host: www.borked.com\r\n" |
| 2138 | "Connection: keep-alive\r\n\r\n"), |
| 2139 | }; |
| 2140 | |
| 2141 | MockRead data_reads1[] = { |
| 2142 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2143 | "Connection: keep-alive\r\n" |
| 2144 | "Content-Length: 22\r\n\r\n" |
| 2145 | "This server is borked." |
| 2146 | "Bonus data!"), |
| 2147 | }; |
| 2148 | |
| 2149 | MockWrite data_writes2[] = { |
| 2150 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2151 | "Host: www.borked.com\r\n" |
| 2152 | "Connection: keep-alive\r\n\r\n"), |
| 2153 | }; |
| 2154 | |
| 2155 | MockRead data_reads2[] = { |
| 2156 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2157 | "Content-Length: 3\r\n\r\n" |
| 2158 | "foo"), |
| 2159 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2160 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2161 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2162 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2163 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2164 | |
| 2165 | TestCompletionCallback callback; |
| 2166 | HttpRequestInfo request1; |
| 2167 | request1.method = "GET"; |
| 2168 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2169 | request1.traffic_annotation = |
| 2170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2171 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2172 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2173 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2174 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2175 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2176 | |
| 2177 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2178 | ASSERT_TRUE(response1); |
| 2179 | ASSERT_TRUE(response1->headers); |
| 2180 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2181 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2182 | |
| 2183 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2184 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2185 | EXPECT_EQ("This server is borked.", response_data1); |
| 2186 | // Deleting the transaction attempts to release the socket back into the |
| 2187 | // socket pool. |
| 2188 | trans1.reset(); |
| 2189 | |
| 2190 | HttpRequestInfo request2; |
| 2191 | request2.method = "GET"; |
| 2192 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2193 | request2.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 trans2 = |
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 | rv = trans2->Start(&request2, 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* response2 = trans2->GetResponseInfo(); |
| 2202 | ASSERT_TRUE(response2); |
| 2203 | ASSERT_TRUE(response2->headers); |
| 2204 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2205 | |
| 2206 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2207 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2208 | EXPECT_EQ("foo", response_data2); |
| 2209 | } |
| 2210 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2211 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2212 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2213 | MockWrite data_writes1[] = { |
| 2214 | MockWrite("GET / HTTP/1.1\r\n" |
| 2215 | "Host: www.borked.com\r\n" |
| 2216 | "Connection: keep-alive\r\n\r\n"), |
| 2217 | }; |
| 2218 | |
| 2219 | MockRead data_reads1[] = { |
| 2220 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2221 | "Connection: keep-alive\r\n" |
| 2222 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2223 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2224 | MockRead("0\r\n\r\nBonus data!"), |
| 2225 | }; |
| 2226 | |
| 2227 | MockWrite data_writes2[] = { |
| 2228 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2229 | "Host: www.borked.com\r\n" |
| 2230 | "Connection: keep-alive\r\n\r\n"), |
| 2231 | }; |
| 2232 | |
| 2233 | MockRead data_reads2[] = { |
| 2234 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2235 | "Content-Length: 3\r\n\r\n" |
| 2236 | "foo"), |
| 2237 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2238 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2239 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2240 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2241 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2242 | |
| 2243 | TestCompletionCallback callback; |
| 2244 | HttpRequestInfo request1; |
| 2245 | request1.method = "GET"; |
| 2246 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2247 | request1.traffic_annotation = |
| 2248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2249 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2250 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2251 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2252 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2253 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2254 | |
| 2255 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2256 | ASSERT_TRUE(response1); |
| 2257 | ASSERT_TRUE(response1->headers); |
| 2258 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2259 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2260 | |
| 2261 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2262 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2263 | EXPECT_EQ("This server is borked.", response_data1); |
| 2264 | // Deleting the transaction attempts to release the socket back into the |
| 2265 | // socket pool. |
| 2266 | trans1.reset(); |
| 2267 | |
| 2268 | HttpRequestInfo request2; |
| 2269 | request2.method = "GET"; |
| 2270 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2271 | request2.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 trans2 = |
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 | rv = trans2->Start(&request2, 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* response2 = trans2->GetResponseInfo(); |
| 2280 | ASSERT_TRUE(response2); |
| 2281 | ASSERT_TRUE(response2->headers); |
| 2282 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2283 | |
| 2284 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2285 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2286 | EXPECT_EQ("foo", response_data2); |
| 2287 | } |
| 2288 | |
| 2289 | // This is a little different from the others - it tests the case that the |
| 2290 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2291 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2292 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2293 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2295 | MockWrite data_writes1[] = { |
| 2296 | MockWrite("GET / HTTP/1.1\r\n" |
| 2297 | "Host: www.borked.com\r\n" |
| 2298 | "Connection: keep-alive\r\n\r\n"), |
| 2299 | }; |
| 2300 | |
| 2301 | MockRead data_reads1[] = { |
| 2302 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2303 | "Connection: keep-alive\r\n" |
| 2304 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2305 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2306 | MockRead("0\r\n\r\nBonus data!"), |
| 2307 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2308 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2309 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2310 | |
| 2311 | TestCompletionCallback callback; |
| 2312 | HttpRequestInfo request1; |
| 2313 | request1.method = "GET"; |
| 2314 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2315 | request1.traffic_annotation = |
| 2316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2317 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2318 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2319 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2320 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2321 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2322 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2323 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2324 | ASSERT_TRUE(response1); |
| 2325 | ASSERT_TRUE(response1->headers); |
| 2326 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2327 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2328 | |
| 2329 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2330 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2331 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2332 | |
| 2333 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2334 | // socket can't be reused, rather than returning it to the socket pool. |
| 2335 | base::RunLoop().RunUntilIdle(); |
| 2336 | |
| 2337 | // There should be no idle sockets in the pool. |
| 2338 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2339 | } |
| 2340 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2341 | // Test the request-challenge-retry sequence for basic auth. |
| 2342 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2343 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2344 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2345 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2346 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2347 | request.traffic_annotation = |
| 2348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2349 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2350 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2351 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2354 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2355 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2356 | MockWrite( |
| 2357 | "GET / HTTP/1.1\r\n" |
| 2358 | "Host: www.example.org\r\n" |
| 2359 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2360 | }; |
| 2361 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2362 | MockRead data_reads1[] = { |
| 2363 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2364 | // Give a couple authenticate options (only the middle one is actually |
| 2365 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2366 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2367 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2368 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2369 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2370 | // Large content-length -- won't matter, as connection will be reset. |
| 2371 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2372 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | }; |
| 2374 | |
| 2375 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2376 | // be issuing -- the final header line contains the credentials. |
| 2377 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2378 | MockWrite( |
| 2379 | "GET / HTTP/1.1\r\n" |
| 2380 | "Host: www.example.org\r\n" |
| 2381 | "Connection: keep-alive\r\n" |
| 2382 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2383 | }; |
| 2384 | |
| 2385 | // Lastly, the server responds with the actual content. |
| 2386 | MockRead data_reads2[] = { |
| 2387 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2388 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2389 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2390 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2391 | }; |
| 2392 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2393 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2394 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2395 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2396 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2398 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2399 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2400 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2402 | |
| 2403 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2404 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2405 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2406 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2407 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2408 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2409 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2410 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2411 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2412 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2413 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2416 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2417 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2418 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2419 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2421 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | |
| 2424 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2425 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2426 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2427 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2428 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2429 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2430 | // The load timing after restart should have a new socket ID, and times after |
| 2431 | // those of the first load timing. |
| 2432 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2433 | load_timing_info2.connect_timing.connect_start); |
| 2434 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2435 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2436 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2437 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2438 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2439 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2441 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2442 | ASSERT_TRUE(response); |
| 2443 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2444 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2445 | } |
| 2446 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2447 | // Test the request-challenge-retry sequence for basic auth. |
| 2448 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2449 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2450 | HttpRequestInfo request; |
| 2451 | request.method = "GET"; |
| 2452 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2453 | request.traffic_annotation = |
| 2454 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2455 | |
| 2456 | TestNetLog log; |
| 2457 | MockHostResolver* resolver = new MockHostResolver(); |
| 2458 | session_deps_.net_log = &log; |
| 2459 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2460 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2461 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2462 | |
| 2463 | resolver->rules()->ClearRules(); |
| 2464 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2465 | |
| 2466 | MockWrite data_writes1[] = { |
| 2467 | MockWrite("GET / HTTP/1.1\r\n" |
| 2468 | "Host: www.example.org\r\n" |
| 2469 | "Connection: keep-alive\r\n\r\n"), |
| 2470 | }; |
| 2471 | |
| 2472 | MockRead data_reads1[] = { |
| 2473 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2474 | // Give a couple authenticate options (only the middle one is actually |
| 2475 | // supported). |
| 2476 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2477 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2478 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2479 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2480 | // Large content-length -- won't matter, as connection will be reset. |
| 2481 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2482 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2483 | }; |
| 2484 | |
| 2485 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2486 | // be issuing -- the final header line contains the credentials. |
| 2487 | MockWrite data_writes2[] = { |
| 2488 | MockWrite("GET / HTTP/1.1\r\n" |
| 2489 | "Host: www.example.org\r\n" |
| 2490 | "Connection: keep-alive\r\n" |
| 2491 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2492 | }; |
| 2493 | |
| 2494 | // Lastly, the server responds with the actual content. |
| 2495 | MockRead data_reads2[] = { |
| 2496 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2497 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2498 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2499 | }; |
| 2500 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2501 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2502 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2503 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2504 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2505 | |
| 2506 | TestCompletionCallback callback1; |
| 2507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2508 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2509 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2510 | |
| 2511 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2512 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2513 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2514 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2515 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2516 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2517 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2518 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2520 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2521 | ASSERT_TRUE(response); |
| 2522 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2523 | |
| 2524 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2525 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2526 | ASSERT_FALSE(endpoint.address().empty()); |
| 2527 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2528 | |
| 2529 | resolver->rules()->ClearRules(); |
| 2530 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2531 | |
| 2532 | TestCompletionCallback callback2; |
| 2533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2534 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2535 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2536 | |
| 2537 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2538 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2539 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2540 | // The load timing after restart should have a new socket ID, and times after |
| 2541 | // those of the first load timing. |
| 2542 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2543 | load_timing_info2.connect_timing.connect_start); |
| 2544 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2546 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2547 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2548 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2549 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2551 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2552 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2553 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2554 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2556 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2557 | ASSERT_FALSE(endpoint.address().empty()); |
| 2558 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2559 | } |
| 2560 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2561 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2562 | // will eventually give up. |
| 2563 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2564 | HttpRequestInfo request; |
| 2565 | request.method = "GET"; |
| 2566 | request.url = GURL("http://www.example.org/"); |
| 2567 | request.traffic_annotation = |
| 2568 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2569 | |
| 2570 | TestNetLog log; |
| 2571 | session_deps_.net_log = &log; |
| 2572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2573 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2574 | |
| 2575 | MockWrite data_writes[] = { |
| 2576 | MockWrite("GET / HTTP/1.1\r\n" |
| 2577 | "Host: www.example.org\r\n" |
| 2578 | "Connection: keep-alive\r\n\r\n"), |
| 2579 | }; |
| 2580 | |
| 2581 | MockRead data_reads[] = { |
| 2582 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2583 | // Give a couple authenticate options (only the middle one is actually |
| 2584 | // supported). |
| 2585 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2586 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2587 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2588 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2589 | // Large content-length -- won't matter, as connection will be reset. |
| 2590 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2591 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2592 | }; |
| 2593 | |
| 2594 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2595 | // be issuing -- the final header line contains the credentials. |
| 2596 | MockWrite data_writes_restart[] = { |
| 2597 | MockWrite("GET / HTTP/1.1\r\n" |
| 2598 | "Host: www.example.org\r\n" |
| 2599 | "Connection: keep-alive\r\n" |
| 2600 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2601 | }; |
| 2602 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2603 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2604 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2605 | |
| 2606 | TestCompletionCallback callback; |
| 2607 | int rv = callback.GetResult( |
| 2608 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2609 | |
| 2610 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2611 | for (int i = 0; i < 32; i++) { |
| 2612 | // Check the previous response was a 401. |
| 2613 | EXPECT_THAT(rv, IsOk()); |
| 2614 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2615 | ASSERT_TRUE(response); |
| 2616 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2617 | |
| 2618 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2619 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2620 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2621 | data_restarts.back().get()); |
| 2622 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2623 | callback.callback())); |
| 2624 | } |
| 2625 | |
| 2626 | // After too many tries, the transaction should have given up. |
| 2627 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2628 | } |
| 2629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2630 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2631 | HttpRequestInfo request; |
| 2632 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2633 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2634 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2635 | request.traffic_annotation = |
| 2636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2640 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2641 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2642 | MockWrite( |
| 2643 | "GET / HTTP/1.1\r\n" |
| 2644 | "Host: www.example.org\r\n" |
| 2645 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2646 | }; |
| 2647 | |
| 2648 | MockRead data_reads[] = { |
| 2649 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2650 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2651 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2652 | // Large content-length -- won't matter, as connection will be reset. |
| 2653 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2654 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2655 | }; |
| 2656 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2657 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2658 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2659 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2660 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2661 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2663 | |
| 2664 | rv = callback.WaitForResult(); |
| 2665 | EXPECT_EQ(0, rv); |
| 2666 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2667 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2668 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2669 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2672 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2673 | ASSERT_TRUE(response); |
| 2674 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2675 | } |
| 2676 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2677 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2678 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2679 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2680 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2681 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2682 | // reused. See http://crbug.com/544255. |
| 2683 | for (int i = 0; i < 2; ++i) { |
| 2684 | HttpRequestInfo request; |
| 2685 | request.method = "GET"; |
| 2686 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2687 | request.traffic_annotation = |
| 2688 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2689 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2690 | TestNetLog log; |
| 2691 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2693 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2694 | MockWrite data_writes[] = { |
| 2695 | MockWrite(ASYNC, 0, |
| 2696 | "GET / HTTP/1.1\r\n" |
| 2697 | "Host: www.example.org\r\n" |
| 2698 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2700 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2701 | // be issuing -- the final header line contains the credentials. |
| 2702 | MockWrite(ASYNC, 6, |
| 2703 | "GET / HTTP/1.1\r\n" |
| 2704 | "Host: www.example.org\r\n" |
| 2705 | "Connection: keep-alive\r\n" |
| 2706 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2707 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2708 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2709 | MockRead data_reads[] = { |
| 2710 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2711 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2712 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2713 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2714 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2715 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2716 | // Lastly, the server responds with the actual content. |
| 2717 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2718 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2719 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2720 | MockRead(ASYNC, 10, "Hello"), |
| 2721 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2722 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2723 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2724 | data.set_busy_before_sync_reads(true); |
| 2725 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2726 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2727 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2730 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2731 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2732 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2733 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2734 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2735 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2738 | ASSERT_TRUE(response); |
| 2739 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2740 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2741 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2743 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2744 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2745 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2747 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2748 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2749 | TestLoadTimingReused(load_timing_info2); |
| 2750 | // The load timing after restart should have the same socket ID, and times |
| 2751 | // those of the first load timing. |
| 2752 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2753 | load_timing_info2.send_start); |
| 2754 | 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] | 2755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2756 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2757 | ASSERT_TRUE(response); |
| 2758 | EXPECT_FALSE(response->auth_challenge); |
| 2759 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2761 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2763 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2764 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2765 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2766 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2768 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2769 | } |
| 2770 | |
| 2771 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2772 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2773 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2774 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2776 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2777 | request.traffic_annotation = |
| 2778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2781 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2783 | MockWrite("GET / HTTP/1.1\r\n" |
| 2784 | "Host: www.example.org\r\n" |
| 2785 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2787 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2788 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | MockWrite("GET / HTTP/1.1\r\n" |
| 2790 | "Host: www.example.org\r\n" |
| 2791 | "Connection: keep-alive\r\n" |
| 2792 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | }; |
| 2794 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | MockRead data_reads1[] = { |
| 2796 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2797 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2798 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | |
| 2800 | // Lastly, the server responds with the actual content. |
| 2801 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2802 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2803 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2804 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | }; |
| 2806 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2807 | // An incorrect reconnect would cause this to be read. |
| 2808 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2809 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2810 | }; |
| 2811 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2812 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2813 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2814 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2817 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2819 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2820 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2822 | |
| 2823 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2824 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2826 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2827 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2828 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2830 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2832 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2834 | |
| 2835 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2838 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2839 | ASSERT_TRUE(response); |
| 2840 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2841 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2842 | } |
| 2843 | |
| 2844 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2845 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2846 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2847 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2849 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2850 | request.traffic_annotation = |
| 2851 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2854 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2855 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2856 | MockWrite("GET / HTTP/1.1\r\n" |
| 2857 | "Host: www.example.org\r\n" |
| 2858 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2860 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2861 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2862 | MockWrite("GET / HTTP/1.1\r\n" |
| 2863 | "Host: www.example.org\r\n" |
| 2864 | "Connection: keep-alive\r\n" |
| 2865 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2866 | }; |
| 2867 | |
| 2868 | // Respond with 5 kb of response body. |
| 2869 | std::string large_body_string("Unauthorized"); |
| 2870 | large_body_string.append(5 * 1024, ' '); |
| 2871 | large_body_string.append("\r\n"); |
| 2872 | |
| 2873 | MockRead data_reads1[] = { |
| 2874 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2875 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2876 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2877 | // 5134 = 12 + 5 * 1024 + 2 |
| 2878 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2879 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2880 | |
| 2881 | // Lastly, the server responds with the actual content. |
| 2882 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2883 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2884 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2885 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2886 | }; |
| 2887 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2888 | // An incorrect reconnect would cause this to be read. |
| 2889 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2890 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2891 | }; |
| 2892 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2893 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2894 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2896 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2898 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2901 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2903 | |
| 2904 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2905 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2907 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2908 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2909 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2911 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2913 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2915 | |
| 2916 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2919 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2920 | ASSERT_TRUE(response); |
| 2921 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2922 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2926 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2927 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2928 | HttpRequestInfo request; |
| 2929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2930 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2931 | request.traffic_annotation = |
| 2932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2933 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2935 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2936 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2937 | MockWrite( |
| 2938 | "GET / HTTP/1.1\r\n" |
| 2939 | "Host: www.example.org\r\n" |
| 2940 | "Connection: keep-alive\r\n\r\n"), |
| 2941 | // This simulates the seemingly successful write to a closed connection |
| 2942 | // if the bug is not fixed. |
| 2943 | MockWrite( |
| 2944 | "GET / HTTP/1.1\r\n" |
| 2945 | "Host: www.example.org\r\n" |
| 2946 | "Connection: keep-alive\r\n" |
| 2947 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2948 | }; |
| 2949 | |
| 2950 | MockRead data_reads1[] = { |
| 2951 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2952 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2953 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2954 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2955 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2956 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2957 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2958 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2959 | }; |
| 2960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2961 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2962 | // be issuing -- the final header line contains the credentials. |
| 2963 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2964 | MockWrite( |
| 2965 | "GET / HTTP/1.1\r\n" |
| 2966 | "Host: www.example.org\r\n" |
| 2967 | "Connection: keep-alive\r\n" |
| 2968 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2969 | }; |
| 2970 | |
| 2971 | // Lastly, the server responds with the actual content. |
| 2972 | MockRead data_reads2[] = { |
| 2973 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2974 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2975 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2976 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2977 | }; |
| 2978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2979 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2980 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2981 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2982 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2984 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2987 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2989 | |
| 2990 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2991 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2994 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2995 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2997 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2999 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3001 | |
| 3002 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3003 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3005 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3006 | ASSERT_TRUE(response); |
| 3007 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3008 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3009 | } |
| 3010 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3011 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3012 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3013 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3014 | HttpRequestInfo request; |
| 3015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3016 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3017 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3018 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3019 | request.traffic_annotation = |
| 3020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3021 | |
| 3022 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3023 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3024 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3025 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3026 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3027 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3029 | |
| 3030 | // Since we have proxy, should try to establish tunnel. |
| 3031 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3032 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3033 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3034 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3035 | }; |
| 3036 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3037 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3038 | // connection. |
| 3039 | MockRead data_reads1[] = { |
| 3040 | // No credentials. |
| 3041 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3042 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3043 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3044 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3045 | // Since the first connection couldn't be reused, need to establish another |
| 3046 | // once given credentials. |
| 3047 | MockWrite data_writes2[] = { |
| 3048 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3049 | // be issuing -- the final header line contains the credentials. |
| 3050 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3051 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3052 | "Proxy-Connection: keep-alive\r\n" |
| 3053 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3054 | |
| 3055 | MockWrite("GET / HTTP/1.1\r\n" |
| 3056 | "Host: www.example.org\r\n" |
| 3057 | "Connection: keep-alive\r\n\r\n"), |
| 3058 | }; |
| 3059 | |
| 3060 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3061 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3062 | |
| 3063 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3064 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3065 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3066 | MockRead(SYNCHRONOUS, "hello"), |
| 3067 | }; |
| 3068 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3069 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3070 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3071 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3072 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3073 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3075 | |
| 3076 | TestCompletionCallback callback1; |
| 3077 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3078 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3079 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3080 | |
| 3081 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3083 | |
| 3084 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3085 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3086 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3087 | log.GetEntries(&entries); |
| 3088 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3089 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3090 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3091 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3092 | entries, pos, |
| 3093 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3094 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3095 | |
| 3096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3097 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3099 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3100 | EXPECT_EQ(407, response->headers->response_code()); |
| 3101 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3102 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3103 | |
| 3104 | LoadTimingInfo load_timing_info; |
| 3105 | // CONNECT requests and responses are handled at the connect job level, so |
| 3106 | // the transaction does not yet have a connection. |
| 3107 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3108 | |
| 3109 | TestCompletionCallback callback2; |
| 3110 | |
| 3111 | rv = |
| 3112 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3114 | |
| 3115 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3116 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3117 | |
| 3118 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3119 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3120 | |
| 3121 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3122 | EXPECT_EQ(200, response->headers->response_code()); |
| 3123 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3124 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3125 | |
| 3126 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3127 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3128 | |
| 3129 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3130 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3131 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3132 | |
| 3133 | trans.reset(); |
| 3134 | session->CloseAllConnections(); |
| 3135 | } |
| 3136 | |
| 3137 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3138 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3139 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3140 | HttpRequestInfo request; |
| 3141 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3142 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3143 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3144 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3145 | request.traffic_annotation = |
| 3146 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3147 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3148 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3149 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3150 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3151 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3152 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3153 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3155 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3156 | // Since we have proxy, should try to establish tunnel. |
| 3157 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3158 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3159 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3160 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3161 | }; |
| 3162 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3163 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3164 | // connection. |
| 3165 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3166 | // No credentials. |
| 3167 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3168 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3169 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3170 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3171 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3172 | MockWrite data_writes2[] = { |
| 3173 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3174 | // be issuing -- the final header line contains the credentials. |
| 3175 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3176 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3177 | "Proxy-Connection: keep-alive\r\n" |
| 3178 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3179 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3180 | MockWrite("GET / HTTP/1.1\r\n" |
| 3181 | "Host: www.example.org\r\n" |
| 3182 | "Connection: keep-alive\r\n\r\n"), |
| 3183 | }; |
| 3184 | |
| 3185 | MockRead data_reads2[] = { |
| 3186 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3187 | |
| 3188 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3189 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3190 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3191 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3192 | }; |
| 3193 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3194 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3195 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3196 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3197 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3198 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3201 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3202 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3203 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3204 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3206 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3207 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3208 | |
| 3209 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3210 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3211 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3212 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3213 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3214 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3215 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3216 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3217 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3218 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3219 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3220 | |
| 3221 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3222 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3223 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3224 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3225 | EXPECT_EQ(407, response->headers->response_code()); |
| 3226 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3227 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3228 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3229 | LoadTimingInfo load_timing_info; |
| 3230 | // CONNECT requests and responses are handled at the connect job level, so |
| 3231 | // the transaction does not yet have a connection. |
| 3232 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3234 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3236 | rv = trans->RestartWithAuth( |
| 3237 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3239 | |
| 3240 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3242 | |
| 3243 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3244 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3245 | |
| 3246 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3247 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3248 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3249 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3250 | |
| 3251 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3252 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3253 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3254 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3255 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3256 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3257 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3258 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3259 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3260 | } |
| 3261 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3262 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3263 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3264 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3265 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3266 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3267 | // reused. See http://crbug.com/544255. |
| 3268 | for (int i = 0; i < 2; ++i) { |
| 3269 | HttpRequestInfo request; |
| 3270 | request.method = "GET"; |
| 3271 | request.url = GURL("https://www.example.org/"); |
| 3272 | // Ensure that proxy authentication is attempted even |
| 3273 | // when the no authentication data flag is set. |
| 3274 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3275 | request.traffic_annotation = |
| 3276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3278 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3279 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3280 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3281 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3282 | BoundTestNetLog log; |
| 3283 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3287 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3288 | // Since we have proxy, should try to establish tunnel. |
| 3289 | MockWrite data_writes1[] = { |
| 3290 | MockWrite(ASYNC, 0, |
| 3291 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3292 | "Host: www.example.org:443\r\n" |
| 3293 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3295 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3296 | // be issuing -- the final header line contains the credentials. |
| 3297 | MockWrite(ASYNC, 3, |
| 3298 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3299 | "Host: www.example.org:443\r\n" |
| 3300 | "Proxy-Connection: keep-alive\r\n" |
| 3301 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3302 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3304 | // The proxy responds to the connect with a 407, using a persistent |
| 3305 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3306 | MockRead data_reads1[] = { |
| 3307 | // No credentials. |
| 3308 | MockRead(ASYNC, 1, |
| 3309 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3310 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3311 | "Proxy-Connection: keep-alive\r\n" |
| 3312 | "Content-Length: 10\r\n\r\n"), |
| 3313 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3314 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3315 | // Wrong credentials (wrong password). |
| 3316 | MockRead(ASYNC, 4, |
| 3317 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3318 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3319 | "Proxy-Connection: keep-alive\r\n" |
| 3320 | "Content-Length: 10\r\n\r\n"), |
| 3321 | // No response body because the test stops reading here. |
| 3322 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3323 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3324 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3325 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3326 | data1.set_busy_before_sync_reads(true); |
| 3327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3328 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3331 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3332 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3334 | TestNetLogEntry::List entries; |
| 3335 | log.GetEntries(&entries); |
| 3336 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3337 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3338 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3339 | ExpectLogContainsSomewhere( |
| 3340 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3341 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3342 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | ASSERT_TRUE(response); |
| 3346 | ASSERT_TRUE(response->headers); |
| 3347 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3348 | EXPECT_EQ(407, response->headers->response_code()); |
| 3349 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3350 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3351 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3352 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3353 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3355 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3356 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3357 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3360 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3361 | ASSERT_TRUE(response); |
| 3362 | ASSERT_TRUE(response->headers); |
| 3363 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3364 | EXPECT_EQ(407, response->headers->response_code()); |
| 3365 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3366 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3367 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3368 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3369 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3370 | // out of scope. |
| 3371 | session->CloseAllConnections(); |
| 3372 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3376 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3377 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3378 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3379 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3380 | // reused. See http://crbug.com/544255. |
| 3381 | for (int i = 0; i < 2; ++i) { |
| 3382 | HttpRequestInfo request; |
| 3383 | request.method = "GET"; |
| 3384 | request.url = GURL("https://www.example.org/"); |
| 3385 | // Ensure that proxy authentication is attempted even |
| 3386 | // when the no authentication data flag is set. |
| 3387 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3388 | request.traffic_annotation = |
| 3389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3390 | |
| 3391 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3392 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3393 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3394 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3395 | BoundTestNetLog log; |
| 3396 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3399 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | |
| 3401 | // Since we have proxy, should try to establish tunnel. |
| 3402 | MockWrite data_writes1[] = { |
| 3403 | MockWrite(ASYNC, 0, |
| 3404 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3405 | "Host: www.example.org:443\r\n" |
| 3406 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3408 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3409 | // be issuing -- the final header line contains the credentials. |
| 3410 | MockWrite(ASYNC, 3, |
| 3411 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3412 | "Host: www.example.org:443\r\n" |
| 3413 | "Proxy-Connection: keep-alive\r\n" |
| 3414 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3415 | }; |
| 3416 | |
| 3417 | // The proxy responds to the connect with a 407, using a persistent |
| 3418 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3419 | MockRead data_reads1[] = { |
| 3420 | // No credentials. |
| 3421 | MockRead(ASYNC, 1, |
| 3422 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3423 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3424 | "Content-Length: 10\r\n\r\n"), |
| 3425 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3426 | |
| 3427 | // Wrong credentials (wrong password). |
| 3428 | MockRead(ASYNC, 4, |
| 3429 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3430 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3431 | "Content-Length: 10\r\n\r\n"), |
| 3432 | // No response body because the test stops reading here. |
| 3433 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3434 | }; |
| 3435 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3436 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3437 | data1.set_busy_before_sync_reads(true); |
| 3438 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3439 | |
| 3440 | TestCompletionCallback callback1; |
| 3441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3442 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3443 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3444 | |
| 3445 | TestNetLogEntry::List entries; |
| 3446 | log.GetEntries(&entries); |
| 3447 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3448 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3449 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3450 | ExpectLogContainsSomewhere( |
| 3451 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3452 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3453 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3455 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3456 | ASSERT_TRUE(response); |
| 3457 | ASSERT_TRUE(response->headers); |
| 3458 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3459 | EXPECT_EQ(407, response->headers->response_code()); |
| 3460 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3461 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3462 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3463 | |
| 3464 | TestCompletionCallback callback2; |
| 3465 | |
| 3466 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3467 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3468 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3469 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3471 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3472 | ASSERT_TRUE(response); |
| 3473 | ASSERT_TRUE(response->headers); |
| 3474 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3475 | EXPECT_EQ(407, response->headers->response_code()); |
| 3476 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3477 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3478 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3479 | |
| 3480 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3481 | // out of scope. |
| 3482 | session->CloseAllConnections(); |
| 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3487 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3488 | // the case the server sends extra data on the original socket, so it can't be |
| 3489 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3490 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3491 | HttpRequestInfo request; |
| 3492 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3493 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3494 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3495 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3496 | request.traffic_annotation = |
| 3497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3498 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3499 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3500 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3501 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3502 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3503 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3504 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3506 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3507 | // Since we have proxy, should try to establish tunnel. |
| 3508 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3509 | MockWrite(ASYNC, 0, |
| 3510 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3511 | "Host: www.example.org:443\r\n" |
| 3512 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3513 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3514 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3515 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3516 | // extra data, so the socket cannot be reused. |
| 3517 | MockRead data_reads1[] = { |
| 3518 | // No credentials. |
| 3519 | MockRead(ASYNC, 1, |
| 3520 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3521 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3522 | "Content-Length: 10\r\n\r\n"), |
| 3523 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3524 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3525 | }; |
| 3526 | |
| 3527 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3528 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3529 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3530 | MockWrite(ASYNC, 0, |
| 3531 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3532 | "Host: www.example.org:443\r\n" |
| 3533 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3534 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3535 | |
| 3536 | MockWrite(ASYNC, 2, |
| 3537 | "GET / HTTP/1.1\r\n" |
| 3538 | "Host: www.example.org\r\n" |
| 3539 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3540 | }; |
| 3541 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3542 | MockRead data_reads2[] = { |
| 3543 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3544 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3545 | MockRead(ASYNC, 3, |
| 3546 | "HTTP/1.1 200 OK\r\n" |
| 3547 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3548 | "Content-Length: 5\r\n\r\n"), |
| 3549 | // No response body because the test stops reading here. |
| 3550 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3551 | }; |
| 3552 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3553 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3555 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3556 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3558 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3559 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3561 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3562 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3563 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3564 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3565 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3567 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3568 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3569 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3570 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3571 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3572 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3573 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3574 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3575 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3576 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3577 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3578 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3579 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3580 | ASSERT_TRUE(response); |
| 3581 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3582 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3583 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3584 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3585 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3586 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3587 | LoadTimingInfo load_timing_info; |
| 3588 | // CONNECT requests and responses are handled at the connect job level, so |
| 3589 | // the transaction does not yet have a connection. |
| 3590 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3591 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3592 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3593 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3594 | rv = |
| 3595 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3596 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3597 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3598 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3599 | EXPECT_EQ(200, response->headers->response_code()); |
| 3600 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3601 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3602 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | // The password prompt info should not be set. |
| 3604 | EXPECT_FALSE(response->auth_challenge); |
| 3605 | |
| 3606 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3607 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3608 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3609 | |
| 3610 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3611 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3612 | } |
| 3613 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3614 | // Test the case a proxy closes a socket while the challenge body is being |
| 3615 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3616 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3617 | HttpRequestInfo request; |
| 3618 | request.method = "GET"; |
| 3619 | request.url = GURL("https://www.example.org/"); |
| 3620 | // Ensure that proxy authentication is attempted even |
| 3621 | // when the no authentication data flag is set. |
| 3622 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3623 | request.traffic_annotation = |
| 3624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3625 | |
| 3626 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3627 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3628 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3629 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3632 | |
| 3633 | // Since we have proxy, should try to establish tunnel. |
| 3634 | MockWrite data_writes1[] = { |
| 3635 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3636 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3637 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3638 | }; |
| 3639 | |
| 3640 | // The proxy responds to the connect with a 407, using a persistent |
| 3641 | // connection. |
| 3642 | MockRead data_reads1[] = { |
| 3643 | // No credentials. |
| 3644 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3645 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3646 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3647 | // Server hands up in the middle of the body. |
| 3648 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3649 | }; |
| 3650 | |
| 3651 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3652 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3653 | // be issuing -- the final header line contains the credentials. |
| 3654 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3655 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3656 | "Proxy-Connection: keep-alive\r\n" |
| 3657 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3658 | |
| 3659 | MockWrite("GET / HTTP/1.1\r\n" |
| 3660 | "Host: www.example.org\r\n" |
| 3661 | "Connection: keep-alive\r\n\r\n"), |
| 3662 | }; |
| 3663 | |
| 3664 | MockRead data_reads2[] = { |
| 3665 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3666 | |
| 3667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3669 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3670 | MockRead(SYNCHRONOUS, "hello"), |
| 3671 | }; |
| 3672 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3673 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3674 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3675 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3676 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3677 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3679 | |
| 3680 | TestCompletionCallback callback; |
| 3681 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3682 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3683 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3686 | ASSERT_TRUE(response); |
| 3687 | ASSERT_TRUE(response->headers); |
| 3688 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3689 | EXPECT_EQ(407, response->headers->response_code()); |
| 3690 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3692 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3693 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3695 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3696 | ASSERT_TRUE(response); |
| 3697 | ASSERT_TRUE(response->headers); |
| 3698 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3699 | EXPECT_EQ(200, response->headers->response_code()); |
| 3700 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3702 | EXPECT_EQ("hello", body); |
| 3703 | } |
| 3704 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3705 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3706 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3707 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3708 | HttpRequestInfo request; |
| 3709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3710 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3711 | request.traffic_annotation = |
| 3712 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3713 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3714 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3715 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3716 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3721 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3722 | // Since we have proxy, should try to establish tunnel. |
| 3723 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3724 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3725 | "Host: www.example.org:443\r\n" |
| 3726 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3727 | }; |
| 3728 | |
| 3729 | // The proxy responds to the connect with a 407. |
| 3730 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3731 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3732 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3733 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3734 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3735 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3736 | }; |
| 3737 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3738 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3741 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3742 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3743 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3745 | |
| 3746 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3749 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3750 | ASSERT_TRUE(response); |
| 3751 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3752 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3753 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3754 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3755 | |
| 3756 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3757 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3758 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3759 | |
| 3760 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3761 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3762 | } |
| 3763 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3764 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3765 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3766 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3767 | HttpRequestInfo request; |
| 3768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3769 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3770 | request.traffic_annotation = |
| 3771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | |
| 3773 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3774 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3775 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3779 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3780 | |
| 3781 | // Since we have proxy, should try to establish tunnel. |
| 3782 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3783 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3784 | "Host: www.example.org:443\r\n" |
| 3785 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3786 | }; |
| 3787 | |
| 3788 | // The proxy responds to the connect with a 407. |
| 3789 | MockRead data_reads[] = { |
| 3790 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3791 | MockRead("X-Foo: bar\r\n"), |
| 3792 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3793 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3794 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3795 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3796 | }; |
| 3797 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3798 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3799 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3800 | |
| 3801 | TestCompletionCallback callback; |
| 3802 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3803 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3804 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3805 | |
| 3806 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3807 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3809 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3810 | ASSERT_TRUE(response); |
| 3811 | ASSERT_TRUE(response->headers); |
| 3812 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3813 | EXPECT_EQ(407, response->headers->response_code()); |
| 3814 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3815 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3816 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3817 | |
| 3818 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3819 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3820 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3821 | |
| 3822 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3823 | session->CloseAllConnections(); |
| 3824 | } |
| 3825 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3826 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3827 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3828 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3829 | HttpRequestInfo request; |
| 3830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3831 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3832 | request.traffic_annotation = |
| 3833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3834 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3835 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3838 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3840 | MockWrite( |
| 3841 | "GET / HTTP/1.1\r\n" |
| 3842 | "Host: www.example.org\r\n" |
| 3843 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3844 | }; |
| 3845 | |
| 3846 | MockRead data_reads1[] = { |
| 3847 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3848 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3849 | // Large content-length -- won't matter, as connection will be reset. |
| 3850 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3851 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3852 | }; |
| 3853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3854 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3855 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3857 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3861 | |
| 3862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3863 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3864 | } |
| 3865 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3866 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3867 | // through a non-authenticating proxy. The request should fail with |
| 3868 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3869 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3870 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3871 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3872 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3873 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3874 | HttpRequestInfo request; |
| 3875 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3876 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3877 | request.traffic_annotation = |
| 3878 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3879 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3880 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3881 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3882 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3883 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3885 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3886 | // Since we have proxy, should try to establish tunnel. |
| 3887 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3888 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3889 | "Host: www.example.org:443\r\n" |
| 3890 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3891 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3892 | MockWrite("GET / HTTP/1.1\r\n" |
| 3893 | "Host: www.example.org\r\n" |
| 3894 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3895 | }; |
| 3896 | |
| 3897 | MockRead data_reads1[] = { |
| 3898 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3899 | |
| 3900 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3901 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3902 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3903 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3904 | }; |
| 3905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3906 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3907 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3908 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3909 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3911 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3915 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3917 | |
| 3918 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3919 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3920 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3921 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3922 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3923 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3924 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3925 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3926 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3927 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3928 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3929 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3930 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3931 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3932 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3933 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3934 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3935 | HttpRequestInfo request; |
| 3936 | request.method = "GET"; |
| 3937 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3938 | request.traffic_annotation = |
| 3939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | |
| 3941 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3942 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3943 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3944 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3945 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3946 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3947 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3948 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3949 | mock_handler->set_allows_default_credentials(true); |
| 3950 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3951 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3952 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3953 | |
| 3954 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3955 | NetLog net_log; |
| 3956 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3957 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3958 | |
| 3959 | // Since we have proxy, should try to establish tunnel. |
| 3960 | MockWrite data_writes1[] = { |
| 3961 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3962 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3963 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3964 | }; |
| 3965 | |
| 3966 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3967 | // connection. |
| 3968 | MockRead data_reads1[] = { |
| 3969 | // No credentials. |
| 3970 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3971 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3972 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3973 | }; |
| 3974 | |
| 3975 | // Since the first connection couldn't be reused, need to establish another |
| 3976 | // once given credentials. |
| 3977 | MockWrite data_writes2[] = { |
| 3978 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3979 | // be issuing -- the final header line contains the credentials. |
| 3980 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3981 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3982 | "Proxy-Connection: keep-alive\r\n" |
| 3983 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3984 | |
| 3985 | MockWrite("GET / HTTP/1.1\r\n" |
| 3986 | "Host: www.example.org\r\n" |
| 3987 | "Connection: keep-alive\r\n\r\n"), |
| 3988 | }; |
| 3989 | |
| 3990 | MockRead data_reads2[] = { |
| 3991 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3992 | |
| 3993 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3994 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3995 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3996 | MockRead(SYNCHRONOUS, "hello"), |
| 3997 | }; |
| 3998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3999 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4001 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4002 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4003 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4004 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4005 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4006 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4007 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4008 | |
| 4009 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4010 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4011 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4012 | |
| 4013 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4014 | ASSERT_TRUE(response); |
| 4015 | ASSERT_TRUE(response->headers); |
| 4016 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4017 | EXPECT_EQ(407, response->headers->response_code()); |
| 4018 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4019 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4020 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4021 | |
| 4022 | LoadTimingInfo load_timing_info; |
| 4023 | // CONNECT requests and responses are handled at the connect job level, so |
| 4024 | // the transaction does not yet have a connection. |
| 4025 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4026 | |
| 4027 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4028 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4029 | response = trans->GetResponseInfo(); |
| 4030 | ASSERT_TRUE(response); |
| 4031 | ASSERT_TRUE(response->headers); |
| 4032 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4033 | EXPECT_EQ(200, response->headers->response_code()); |
| 4034 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4035 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4036 | |
| 4037 | // The password prompt info should not be set. |
| 4038 | EXPECT_FALSE(response->auth_challenge); |
| 4039 | |
| 4040 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4041 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4042 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4043 | |
| 4044 | trans.reset(); |
| 4045 | session->CloseAllConnections(); |
| 4046 | } |
| 4047 | |
| 4048 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4049 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4050 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4051 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4052 | HttpRequestInfo request; |
| 4053 | request.method = "GET"; |
| 4054 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4055 | request.traffic_annotation = |
| 4056 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4057 | |
| 4058 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4059 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4060 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4061 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4063 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4065 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4066 | mock_handler->set_allows_default_credentials(true); |
| 4067 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4068 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4069 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4070 | |
| 4071 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4072 | NetLog net_log; |
| 4073 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4074 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4075 | |
| 4076 | // Should try to establish tunnel. |
| 4077 | MockWrite data_writes1[] = { |
| 4078 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4079 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4080 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4081 | |
| 4082 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4083 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4084 | "Proxy-Connection: keep-alive\r\n" |
| 4085 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4086 | }; |
| 4087 | |
| 4088 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4089 | // connection. |
| 4090 | MockRead data_reads1[] = { |
| 4091 | // No credentials. |
| 4092 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4093 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4094 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4095 | }; |
| 4096 | |
| 4097 | // Since the first connection was closed, need to establish another once given |
| 4098 | // credentials. |
| 4099 | MockWrite data_writes2[] = { |
| 4100 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4101 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4102 | "Proxy-Connection: keep-alive\r\n" |
| 4103 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4104 | |
| 4105 | MockWrite("GET / HTTP/1.1\r\n" |
| 4106 | "Host: www.example.org\r\n" |
| 4107 | "Connection: keep-alive\r\n\r\n"), |
| 4108 | }; |
| 4109 | |
| 4110 | MockRead data_reads2[] = { |
| 4111 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4112 | |
| 4113 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4114 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4115 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4116 | MockRead(SYNCHRONOUS, "hello"), |
| 4117 | }; |
| 4118 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4119 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4120 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4121 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4122 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4123 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4124 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4125 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4128 | |
| 4129 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4130 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4131 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4132 | |
| 4133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4134 | ASSERT_TRUE(response); |
| 4135 | ASSERT_TRUE(response->headers); |
| 4136 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4137 | EXPECT_EQ(407, response->headers->response_code()); |
| 4138 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4139 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4140 | EXPECT_FALSE(response->auth_challenge); |
| 4141 | |
| 4142 | LoadTimingInfo load_timing_info; |
| 4143 | // CONNECT requests and responses are handled at the connect job level, so |
| 4144 | // the transaction does not yet have a connection. |
| 4145 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4146 | |
| 4147 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4148 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4149 | |
| 4150 | response = trans->GetResponseInfo(); |
| 4151 | ASSERT_TRUE(response); |
| 4152 | ASSERT_TRUE(response->headers); |
| 4153 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4154 | EXPECT_EQ(200, response->headers->response_code()); |
| 4155 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4156 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4157 | |
| 4158 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4159 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | |
| 4161 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4162 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4163 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4164 | |
| 4165 | trans.reset(); |
| 4166 | session->CloseAllConnections(); |
| 4167 | } |
| 4168 | |
| 4169 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4170 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4171 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4172 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4174 | HttpRequestInfo request; |
| 4175 | request.method = "GET"; |
| 4176 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4177 | request.traffic_annotation = |
| 4178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4179 | |
| 4180 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4181 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4182 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4183 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4184 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4185 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4186 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4187 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4188 | mock_handler->set_allows_default_credentials(true); |
| 4189 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4190 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4191 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | |
| 4193 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4194 | NetLog net_log; |
| 4195 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4196 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | |
| 4198 | // Should try to establish tunnel. |
| 4199 | MockWrite data_writes1[] = { |
| 4200 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4201 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4203 | |
| 4204 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4205 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4206 | "Proxy-Connection: keep-alive\r\n" |
| 4207 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4208 | }; |
| 4209 | |
| 4210 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4211 | // second request is sent. |
| 4212 | MockRead data_reads1[] = { |
| 4213 | // No credentials. |
| 4214 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4215 | MockRead("Content-Length: 0\r\n"), |
| 4216 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4217 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4218 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4219 | }; |
| 4220 | |
| 4221 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4222 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4223 | // request. |
| 4224 | MockWrite data_writes2[] = { |
| 4225 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4226 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4227 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4228 | }; |
| 4229 | |
| 4230 | // The proxy, having had more than enough of us, just hangs up. |
| 4231 | MockRead data_reads2[] = { |
| 4232 | // No credentials. |
| 4233 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4234 | }; |
| 4235 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4236 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4237 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4238 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4239 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4241 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4243 | |
| 4244 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4245 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4246 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4247 | |
| 4248 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4249 | ASSERT_TRUE(response); |
| 4250 | ASSERT_TRUE(response->headers); |
| 4251 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4252 | EXPECT_EQ(407, response->headers->response_code()); |
| 4253 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4254 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4255 | EXPECT_FALSE(response->auth_challenge); |
| 4256 | |
| 4257 | LoadTimingInfo load_timing_info; |
| 4258 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4259 | |
| 4260 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4261 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4262 | |
| 4263 | trans.reset(); |
| 4264 | session->CloseAllConnections(); |
| 4265 | } |
| 4266 | |
| 4267 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4268 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4269 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4270 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4271 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4272 | HttpRequestInfo request; |
| 4273 | request.method = "GET"; |
| 4274 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4275 | request.traffic_annotation = |
| 4276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4277 | |
| 4278 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4279 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4280 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4281 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4282 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4283 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4284 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4285 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | mock_handler->set_allows_default_credentials(true); |
| 4287 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4288 | HttpAuth::AUTH_PROXY); |
| 4289 | // Add another handler for the second challenge. It supports default |
| 4290 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4291 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4292 | mock_handler->set_allows_default_credentials(true); |
| 4293 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4294 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4295 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4296 | |
| 4297 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4298 | NetLog net_log; |
| 4299 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4300 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4301 | |
| 4302 | // Should try to establish tunnel. |
| 4303 | MockWrite data_writes1[] = { |
| 4304 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4305 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4307 | }; |
| 4308 | |
| 4309 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4310 | // connection. |
| 4311 | MockRead data_reads1[] = { |
| 4312 | // No credentials. |
| 4313 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4314 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4315 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4316 | }; |
| 4317 | |
| 4318 | // Since the first connection was closed, need to establish another once given |
| 4319 | // credentials. |
| 4320 | MockWrite data_writes2[] = { |
| 4321 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4322 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4323 | "Proxy-Connection: keep-alive\r\n" |
| 4324 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4325 | }; |
| 4326 | |
| 4327 | MockRead data_reads2[] = { |
| 4328 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4329 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4330 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4331 | }; |
| 4332 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4333 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4335 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4336 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4337 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4339 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4340 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4341 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4342 | |
| 4343 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4344 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4345 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4346 | |
| 4347 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4348 | ASSERT_TRUE(response); |
| 4349 | ASSERT_TRUE(response->headers); |
| 4350 | EXPECT_EQ(407, response->headers->response_code()); |
| 4351 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4352 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4353 | EXPECT_FALSE(response->auth_challenge); |
| 4354 | |
| 4355 | LoadTimingInfo load_timing_info; |
| 4356 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4357 | |
| 4358 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4359 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4360 | response = trans->GetResponseInfo(); |
| 4361 | ASSERT_TRUE(response); |
| 4362 | ASSERT_TRUE(response->headers); |
| 4363 | EXPECT_EQ(407, response->headers->response_code()); |
| 4364 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4365 | EXPECT_TRUE(response->auth_challenge); |
| 4366 | |
| 4367 | trans.reset(); |
| 4368 | session->CloseAllConnections(); |
| 4369 | } |
| 4370 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4371 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4372 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4373 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4374 | // authentication handshake can continue with the same scheme but with a |
| 4375 | // different identity. |
| 4376 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4377 | HttpRequestInfo request; |
| 4378 | request.method = "GET"; |
| 4379 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4380 | request.traffic_annotation = |
| 4381 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4382 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4383 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4384 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4385 | |
| 4386 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4387 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4388 | mock_handler->set_allows_default_credentials(true); |
| 4389 | mock_handler->set_allows_explicit_credentials(true); |
| 4390 | mock_handler->set_connection_based(true); |
| 4391 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4392 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4393 | HttpAuth::AUTH_SERVER); |
| 4394 | |
| 4395 | // Add another handler for the second challenge. It supports default |
| 4396 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4397 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4398 | mock_handler->set_allows_default_credentials(true); |
| 4399 | mock_handler->set_allows_explicit_credentials(true); |
| 4400 | mock_handler->set_connection_based(true); |
| 4401 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4402 | HttpAuth::AUTH_SERVER); |
| 4403 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4404 | |
| 4405 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4406 | |
| 4407 | MockWrite data_writes1[] = { |
| 4408 | MockWrite("GET / HTTP/1.1\r\n" |
| 4409 | "Host: www.example.org\r\n" |
| 4410 | "Connection: keep-alive\r\n\r\n"), |
| 4411 | }; |
| 4412 | |
| 4413 | MockRead data_reads1[] = { |
| 4414 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4415 | "WWW-Authenticate: Mock\r\n" |
| 4416 | "Connection: keep-alive\r\n\r\n"), |
| 4417 | }; |
| 4418 | |
| 4419 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4420 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4421 | // transaction procceds without an authorization header. |
| 4422 | MockWrite data_writes2[] = { |
| 4423 | MockWrite("GET / HTTP/1.1\r\n" |
| 4424 | "Host: www.example.org\r\n" |
| 4425 | "Connection: keep-alive\r\n\r\n"), |
| 4426 | }; |
| 4427 | |
| 4428 | MockRead data_reads2[] = { |
| 4429 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4430 | "WWW-Authenticate: Mock\r\n" |
| 4431 | "Connection: keep-alive\r\n\r\n"), |
| 4432 | }; |
| 4433 | |
| 4434 | MockWrite data_writes3[] = { |
| 4435 | MockWrite("GET / HTTP/1.1\r\n" |
| 4436 | "Host: www.example.org\r\n" |
| 4437 | "Connection: keep-alive\r\n" |
| 4438 | "Authorization: auth_token\r\n\r\n"), |
| 4439 | }; |
| 4440 | |
| 4441 | MockRead data_reads3[] = { |
| 4442 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4443 | "Content-Length: 5\r\n" |
| 4444 | "Content-Type: text/plain\r\n" |
| 4445 | "Connection: keep-alive\r\n\r\n" |
| 4446 | "Hello"), |
| 4447 | }; |
| 4448 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4449 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4450 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4451 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4452 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4453 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4454 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4455 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4456 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4457 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4458 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4459 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4460 | |
| 4461 | TestCompletionCallback callback; |
| 4462 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4463 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4464 | |
| 4465 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4466 | ASSERT_TRUE(response); |
| 4467 | ASSERT_TRUE(response->headers); |
| 4468 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4469 | |
| 4470 | // The following three tests assert that an authentication challenge was |
| 4471 | // received and that the stack is ready to respond to the challenge using |
| 4472 | // ambient credentials. |
| 4473 | EXPECT_EQ(401, response->headers->response_code()); |
| 4474 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4475 | EXPECT_FALSE(response->auth_challenge); |
| 4476 | |
| 4477 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4478 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4479 | response = trans->GetResponseInfo(); |
| 4480 | ASSERT_TRUE(response); |
| 4481 | ASSERT_TRUE(response->headers); |
| 4482 | |
| 4483 | // The following three tests assert that an authentication challenge was |
| 4484 | // received and that the stack needs explicit credentials before it is ready |
| 4485 | // to respond to the challenge. |
| 4486 | EXPECT_EQ(401, response->headers->response_code()); |
| 4487 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4488 | EXPECT_TRUE(response->auth_challenge); |
| 4489 | |
| 4490 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4491 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4492 | response = trans->GetResponseInfo(); |
| 4493 | ASSERT_TRUE(response); |
| 4494 | ASSERT_TRUE(response->headers); |
| 4495 | EXPECT_EQ(200, response->headers->response_code()); |
| 4496 | |
| 4497 | trans.reset(); |
| 4498 | session->CloseAllConnections(); |
| 4499 | } |
| 4500 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4501 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4502 | // schemes, based on the path of the URL being requests. |
| 4503 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4504 | public: |
| 4505 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4506 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4507 | |
| 4508 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4509 | |
| 4510 | static HostPortPair ProxyHostPortPair() { |
| 4511 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4512 | } |
| 4513 | |
| 4514 | // ProxyResolver implementation. |
| 4515 | int GetProxyForURL(const GURL& url, |
| 4516 | ProxyInfo* results, |
| 4517 | const CompletionCallback& callback, |
| 4518 | std::unique_ptr<Request>* request, |
| 4519 | const NetLogWithSource& /*net_log*/) override { |
| 4520 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4521 | results->set_traffic_annotation( |
| 4522 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4523 | if (url.path() == "/socks4") { |
| 4524 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4525 | return OK; |
| 4526 | } |
| 4527 | if (url.path() == "/socks5") { |
| 4528 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4529 | return OK; |
| 4530 | } |
| 4531 | if (url.path() == "/http") { |
| 4532 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4533 | return OK; |
| 4534 | } |
| 4535 | if (url.path() == "/https") { |
| 4536 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4537 | return OK; |
| 4538 | } |
| 4539 | NOTREACHED(); |
| 4540 | return ERR_NOT_IMPLEMENTED; |
| 4541 | } |
| 4542 | |
| 4543 | private: |
| 4544 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4545 | }; |
| 4546 | |
| 4547 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4548 | : public ProxyResolverFactory { |
| 4549 | public: |
| 4550 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4551 | : ProxyResolverFactory(false) {} |
| 4552 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4553 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4554 | std::unique_ptr<ProxyResolver>* resolver, |
| 4555 | const CompletionCallback& callback, |
| 4556 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4557 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4558 | return OK; |
| 4559 | } |
| 4560 | |
| 4561 | private: |
| 4562 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4563 | }; |
| 4564 | |
| 4565 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4566 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4567 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4568 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4569 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4570 | session_deps_.proxy_resolution_service = |
| 4571 | std::make_unique<ProxyResolutionService>( |
| 4572 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4573 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4574 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4575 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4576 | |
| 4577 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4578 | |
| 4579 | MockWrite socks_writes[] = { |
| 4580 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4581 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4582 | MockWrite(SYNCHRONOUS, |
| 4583 | "GET /socks4 HTTP/1.1\r\n" |
| 4584 | "Host: test\r\n" |
| 4585 | "Connection: keep-alive\r\n\r\n"), |
| 4586 | }; |
| 4587 | MockRead socks_reads[] = { |
| 4588 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4589 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4590 | "Connection: keep-alive\r\n" |
| 4591 | "Content-Length: 15\r\n\r\n" |
| 4592 | "SOCKS4 Response"), |
| 4593 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4594 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4595 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4596 | |
| 4597 | const char kSOCKS5Request[] = { |
| 4598 | 0x05, // Version |
| 4599 | 0x01, // Command (CONNECT) |
| 4600 | 0x00, // Reserved |
| 4601 | 0x03, // Address type (DOMAINNAME) |
| 4602 | 0x04, // Length of domain (4) |
| 4603 | 't', 'e', 's', 't', // Domain string |
| 4604 | 0x00, 0x50, // 16-bit port (80) |
| 4605 | }; |
| 4606 | MockWrite socks5_writes[] = { |
| 4607 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4608 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4609 | MockWrite(SYNCHRONOUS, |
| 4610 | "GET /socks5 HTTP/1.1\r\n" |
| 4611 | "Host: test\r\n" |
| 4612 | "Connection: keep-alive\r\n\r\n"), |
| 4613 | }; |
| 4614 | MockRead socks5_reads[] = { |
| 4615 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4616 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4617 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4618 | "Connection: keep-alive\r\n" |
| 4619 | "Content-Length: 15\r\n\r\n" |
| 4620 | "SOCKS5 Response"), |
| 4621 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4622 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4623 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4624 | |
| 4625 | MockWrite http_writes[] = { |
| 4626 | MockWrite(SYNCHRONOUS, |
| 4627 | "GET http://test/http HTTP/1.1\r\n" |
| 4628 | "Host: test\r\n" |
| 4629 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4630 | }; |
| 4631 | MockRead http_reads[] = { |
| 4632 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4633 | "Proxy-Connection: keep-alive\r\n" |
| 4634 | "Content-Length: 13\r\n\r\n" |
| 4635 | "HTTP Response"), |
| 4636 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4637 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4638 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4639 | |
| 4640 | MockWrite https_writes[] = { |
| 4641 | MockWrite(SYNCHRONOUS, |
| 4642 | "GET http://test/https HTTP/1.1\r\n" |
| 4643 | "Host: test\r\n" |
| 4644 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4645 | }; |
| 4646 | MockRead https_reads[] = { |
| 4647 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4648 | "Proxy-Connection: keep-alive\r\n" |
| 4649 | "Content-Length: 14\r\n\r\n" |
| 4650 | "HTTPS Response"), |
| 4651 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4652 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4653 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4654 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4656 | |
| 4657 | struct TestCase { |
| 4658 | GURL url; |
| 4659 | std::string expected_response; |
| 4660 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4661 | // after the test. |
| 4662 | int expected_idle_socks_sockets; |
| 4663 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4664 | // the test. |
| 4665 | int expected_idle_http_sockets; |
| 4666 | } const kTestCases[] = { |
| 4667 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4668 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4669 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4670 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4671 | }; |
| 4672 | |
| 4673 | for (const auto& test_case : kTestCases) { |
| 4674 | HttpRequestInfo request; |
| 4675 | request.method = "GET"; |
| 4676 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4677 | request.traffic_annotation = |
| 4678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4679 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4680 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4681 | session.get()); |
| 4682 | TestCompletionCallback callback; |
| 4683 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4684 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4685 | |
| 4686 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4687 | ASSERT_TRUE(response); |
| 4688 | ASSERT_TRUE(response->headers); |
| 4689 | EXPECT_EQ(200, response->headers->response_code()); |
| 4690 | std::string response_data; |
| 4691 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4692 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4693 | |
| 4694 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4695 | // the next requests. |
| 4696 | trans.reset(); |
| 4697 | base::RunLoop().RunUntilIdle(); |
| 4698 | |
| 4699 | // Check the number of idle sockets in the pool, to make sure that used |
| 4700 | // sockets are indeed being returned to the socket pool. If each request |
| 4701 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4702 | // pass. |
| 4703 | EXPECT_EQ( |
| 4704 | test_case.expected_idle_socks_sockets, |
| 4705 | session |
| 4706 | ->GetSocketPoolForSOCKSProxy( |
| 4707 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4708 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4709 | ->IdleSocketCount()); |
| 4710 | EXPECT_EQ( |
| 4711 | test_case.expected_idle_http_sockets, |
| 4712 | session |
| 4713 | ->GetSocketPoolForHTTPProxy( |
| 4714 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4715 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4716 | ->IdleSocketCount()); |
| 4717 | } |
| 4718 | } |
| 4719 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4720 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4721 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4722 | HttpRequestInfo request1; |
| 4723 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4724 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4725 | request1.traffic_annotation = |
| 4726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4727 | |
| 4728 | HttpRequestInfo request2; |
| 4729 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4730 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4731 | request2.traffic_annotation = |
| 4732 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4733 | |
| 4734 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4735 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4736 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4737 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4738 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4739 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4740 | |
| 4741 | // Since we have proxy, should try to establish tunnel. |
| 4742 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4743 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4744 | "Host: www.example.org:443\r\n" |
| 4745 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4746 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4747 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4748 | "Host: www.example.org\r\n" |
| 4749 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4750 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4751 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4752 | "Host: www.example.org\r\n" |
| 4753 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4754 | }; |
| 4755 | |
| 4756 | // The proxy responds to the connect with a 407, using a persistent |
| 4757 | // connection. |
| 4758 | MockRead data_reads1[] = { |
| 4759 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4760 | |
| 4761 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4762 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4763 | MockRead(SYNCHRONOUS, "1"), |
| 4764 | |
| 4765 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4766 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4767 | MockRead(SYNCHRONOUS, "22"), |
| 4768 | }; |
| 4769 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4770 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4771 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4772 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4774 | |
| 4775 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4776 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4777 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4778 | |
| 4779 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4781 | |
| 4782 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4783 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4784 | |
| 4785 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4786 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4787 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4788 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4789 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4790 | |
| 4791 | LoadTimingInfo load_timing_info1; |
| 4792 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4793 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4794 | |
| 4795 | trans1.reset(); |
| 4796 | |
| 4797 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4798 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4799 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4800 | |
| 4801 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4803 | |
| 4804 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4806 | |
| 4807 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4808 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4809 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4810 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4811 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4812 | |
| 4813 | LoadTimingInfo load_timing_info2; |
| 4814 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4815 | TestLoadTimingReused(load_timing_info2); |
| 4816 | |
| 4817 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4818 | |
| 4819 | trans2.reset(); |
| 4820 | session->CloseAllConnections(); |
| 4821 | } |
| 4822 | |
| 4823 | // 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] | 4824 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4825 | HttpRequestInfo request1; |
| 4826 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4827 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4828 | request1.traffic_annotation = |
| 4829 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4830 | |
| 4831 | HttpRequestInfo request2; |
| 4832 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4833 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4834 | request2.traffic_annotation = |
| 4835 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4836 | |
| 4837 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4838 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4839 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4840 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4841 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4842 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4843 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4844 | |
| 4845 | // Since we have proxy, should try to establish tunnel. |
| 4846 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4847 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4848 | "Host: www.example.org:443\r\n" |
| 4849 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4850 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4851 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4852 | "Host: www.example.org\r\n" |
| 4853 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4854 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4855 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4856 | "Host: www.example.org\r\n" |
| 4857 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4858 | }; |
| 4859 | |
| 4860 | // The proxy responds to the connect with a 407, using a persistent |
| 4861 | // connection. |
| 4862 | MockRead data_reads1[] = { |
| 4863 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4864 | |
| 4865 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4866 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4867 | MockRead(SYNCHRONOUS, "1"), |
| 4868 | |
| 4869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4870 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4871 | MockRead(SYNCHRONOUS, "22"), |
| 4872 | }; |
| 4873 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4874 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4875 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4876 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4877 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4878 | |
| 4879 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4880 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4881 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4882 | |
| 4883 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4885 | |
| 4886 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4888 | |
| 4889 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4890 | ASSERT_TRUE(response1); |
| 4891 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4892 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4893 | |
| 4894 | LoadTimingInfo load_timing_info1; |
| 4895 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4896 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4897 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4898 | |
| 4899 | trans1.reset(); |
| 4900 | |
| 4901 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4902 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4903 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4904 | |
| 4905 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4907 | |
| 4908 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4910 | |
| 4911 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4912 | ASSERT_TRUE(response2); |
| 4913 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4914 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4915 | |
| 4916 | LoadTimingInfo load_timing_info2; |
| 4917 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4918 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4919 | |
| 4920 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4921 | |
| 4922 | trans2.reset(); |
| 4923 | session->CloseAllConnections(); |
| 4924 | } |
| 4925 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4926 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4927 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4928 | HttpRequestInfo request; |
| 4929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4930 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4931 | request.traffic_annotation = |
| 4932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4933 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4934 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4935 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4936 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4937 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4938 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4940 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4941 | // Since we have proxy, should use full url |
| 4942 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4943 | MockWrite( |
| 4944 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4945 | "Host: www.example.org\r\n" |
| 4946 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4947 | }; |
| 4948 | |
| 4949 | MockRead data_reads1[] = { |
| 4950 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4951 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4952 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4953 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4954 | }; |
| 4955 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4956 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4958 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4959 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4961 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4963 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4964 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4965 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4967 | |
| 4968 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4969 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4970 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4971 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4972 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4973 | TestLoadTimingNotReused(load_timing_info, |
| 4974 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4976 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4977 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4978 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4979 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4980 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4981 | EXPECT_EQ(200, response->headers->response_code()); |
| 4982 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4983 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4984 | |
| 4985 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4986 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4987 | } |
| 4988 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4989 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4990 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4991 | HttpRequestInfo request; |
| 4992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4993 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4994 | request.traffic_annotation = |
| 4995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4996 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4997 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4998 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4999 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5000 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5001 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5003 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5004 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5005 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5006 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5007 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5008 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5009 | spdy::SpdySerializedFrame resp( |
| 5010 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5011 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5012 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5013 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5014 | }; |
| 5015 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5016 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5017 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5018 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5019 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5020 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5022 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5023 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5025 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5027 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5029 | |
| 5030 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5031 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5032 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5033 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5034 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5035 | TestLoadTimingNotReused(load_timing_info, |
| 5036 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5038 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5039 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5040 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5041 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5042 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5043 | |
| 5044 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5045 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5046 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5047 | } |
| 5048 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5049 | // Verifies that a session which races and wins against the owning transaction |
| 5050 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5051 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5052 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5053 | HttpRequestInfo request; |
| 5054 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5055 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5056 | request.traffic_annotation = |
| 5057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5058 | |
| 5059 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5060 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5061 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5062 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5063 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5065 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5066 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5067 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5068 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5069 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5070 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5071 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5072 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5073 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5074 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5075 | }; |
| 5076 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5077 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5078 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5079 | |
| 5080 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5081 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5082 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5083 | |
| 5084 | TestCompletionCallback callback1; |
| 5085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5087 | |
| 5088 | // Stall the hostname resolution begun by the transaction. |
| 5089 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5090 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5092 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5094 | |
| 5095 | // Race a session to the proxy, which completes first. |
| 5096 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5097 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5098 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5099 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5100 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5101 | |
| 5102 | // Unstall the resolution begun by the transaction. |
| 5103 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5104 | session_deps_.host_resolver->ResolveAllPending(); |
| 5105 | |
| 5106 | EXPECT_FALSE(callback1.have_result()); |
| 5107 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5110 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5111 | ASSERT_TRUE(response); |
| 5112 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5113 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5114 | |
| 5115 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5116 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5117 | EXPECT_EQ(kUploadData, response_data); |
| 5118 | } |
| 5119 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5120 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5121 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5122 | HttpRequestInfo request; |
| 5123 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5124 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5125 | request.traffic_annotation = |
| 5126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5127 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5128 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5129 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5130 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5131 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5132 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5134 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5135 | // The first request will be a bare GET, the second request will be a |
| 5136 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5137 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5138 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5139 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5140 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5141 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5142 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5143 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5144 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5145 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5146 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5147 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5148 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5149 | }; |
| 5150 | |
| 5151 | // The first response is a 407 proxy authentication challenge, and the second |
| 5152 | // response will be a 200 response since the second request includes a valid |
| 5153 | // Authorization header. |
| 5154 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5155 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5156 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5157 | spdy::SpdySerializedFrame resp_authentication( |
| 5158 | spdy_util_.ConstructSpdyReplyError( |
| 5159 | "407", kExtraAuthenticationHeaders, |
| 5160 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5161 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5162 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5163 | spdy::SpdySerializedFrame resp_data( |
| 5164 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5165 | spdy::SpdySerializedFrame body_data( |
| 5166 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5167 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5168 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5169 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5170 | CreateMockRead(resp_data, 4), |
| 5171 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5172 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5173 | }; |
| 5174 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5175 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5176 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5177 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5178 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5179 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5180 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5181 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5182 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5184 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5188 | |
| 5189 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5192 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5193 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5194 | ASSERT_TRUE(response); |
| 5195 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5196 | EXPECT_EQ(407, response->headers->response_code()); |
| 5197 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5198 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5200 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5202 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5204 | |
| 5205 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5208 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5209 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5210 | ASSERT_TRUE(response_restart); |
| 5211 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5212 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5213 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5214 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5215 | } |
| 5216 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5217 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5218 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5219 | HttpRequestInfo request; |
| 5220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5221 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5222 | request.traffic_annotation = |
| 5223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5224 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5225 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5226 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5227 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5228 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5229 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5233 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5234 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5235 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5236 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5237 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5238 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5239 | const char get[] = |
| 5240 | "GET / HTTP/1.1\r\n" |
| 5241 | "Host: www.example.org\r\n" |
| 5242 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5243 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5244 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5245 | spdy::SpdySerializedFrame conn_resp( |
| 5246 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5247 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5248 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5249 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5250 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5251 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5252 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5253 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5254 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5255 | |
| 5256 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5257 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5258 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5259 | }; |
| 5260 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5261 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5262 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5263 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5264 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5265 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5266 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5267 | }; |
| 5268 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5269 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5270 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5271 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5272 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5273 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5274 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5275 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5278 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5280 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5282 | |
| 5283 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5284 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5285 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5286 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5287 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5288 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5291 | ASSERT_TRUE(response); |
| 5292 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5294 | |
| 5295 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5296 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5297 | EXPECT_EQ("1234567890", response_data); |
| 5298 | } |
| 5299 | |
| 5300 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5301 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5302 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5303 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5304 | HttpRequestInfo request; |
| 5305 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5306 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5307 | request.traffic_annotation = |
| 5308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5309 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5310 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5311 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5312 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5313 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5314 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5316 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5317 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5318 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5319 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5320 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5321 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5322 | // fetch https://www.example.org/ via SPDY |
| 5323 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5324 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5325 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5326 | spdy::SpdySerializedFrame wrapped_get( |
| 5327 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5328 | spdy::SpdySerializedFrame conn_resp( |
| 5329 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5330 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5331 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5332 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5333 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5334 | spdy::SpdySerializedFrame body( |
| 5335 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5336 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5337 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5338 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5339 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5340 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5342 | |
| 5343 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5344 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5345 | CreateMockWrite(window_update_get_resp, 6), |
| 5346 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5347 | }; |
| 5348 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5349 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5350 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5351 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5352 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5353 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5354 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5355 | }; |
| 5356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5357 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5358 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5359 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5360 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5361 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5363 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5364 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5366 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5367 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5369 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5371 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5372 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5373 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5374 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5375 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5376 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5377 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5378 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5379 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5380 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5381 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5383 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5384 | ASSERT_TRUE(response); |
| 5385 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5386 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5387 | |
| 5388 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5389 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5390 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5394 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5395 | HttpRequestInfo request; |
| 5396 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5397 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5398 | request.traffic_annotation = |
| 5399 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5400 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5401 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5402 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5403 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5404 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5405 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5406 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5409 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5410 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5411 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5412 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5413 | spdy::SpdySerializedFrame get( |
| 5414 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5415 | |
| 5416 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5417 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5418 | }; |
| 5419 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5420 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5421 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5422 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5423 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5424 | }; |
| 5425 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5426 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5427 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5428 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5429 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5430 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5431 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5432 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5433 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5435 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5436 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5438 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5440 | |
| 5441 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5442 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5443 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5444 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5445 | } |
| 5446 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5447 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5448 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5449 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5450 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5451 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5452 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5453 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5454 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5455 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5456 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5457 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5458 | |
| 5459 | HttpRequestInfo request1; |
| 5460 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5461 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5462 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5463 | request1.traffic_annotation = |
| 5464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5465 | |
| 5466 | HttpRequestInfo request2; |
| 5467 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5468 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5469 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5470 | request2.traffic_annotation = |
| 5471 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5472 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5473 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5474 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5475 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5476 | spdy::SpdySerializedFrame conn_resp1( |
| 5477 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5478 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5479 | // Fetch https://www.example.org/ via HTTP. |
| 5480 | const char get1[] = |
| 5481 | "GET / HTTP/1.1\r\n" |
| 5482 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5483 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5484 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5485 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5486 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5487 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5488 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5489 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5490 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5491 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5492 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5493 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5494 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5495 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5496 | spdy::SpdyHeaderBlock connect2_block; |
| 5497 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 5498 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 5499 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5500 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5501 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5502 | spdy::SpdySerializedFrame conn_resp2( |
| 5503 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5504 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5505 | // Fetch https://mail.example.org/ via HTTP. |
| 5506 | const char get2[] = |
| 5507 | "GET / HTTP/1.1\r\n" |
| 5508 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5509 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5510 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5511 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5512 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5513 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5514 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5515 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5516 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5517 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5518 | |
| 5519 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5520 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5521 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5522 | }; |
| 5523 | |
| 5524 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5525 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5526 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5527 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5528 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5529 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5530 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5531 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5532 | }; |
| 5533 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5534 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5535 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5536 | |
| 5537 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5538 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5540 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5542 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5544 | |
| 5545 | TestCompletionCallback callback; |
| 5546 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5547 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5548 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5549 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5550 | |
| 5551 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5552 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5553 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5555 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5556 | ASSERT_TRUE(response); |
| 5557 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5558 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5559 | |
| 5560 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5561 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5562 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5563 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5564 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5565 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5566 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5567 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5568 | |
| 5569 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5570 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5571 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5572 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5573 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5574 | |
| 5575 | // The requests should have different IDs, since they each are using their own |
| 5576 | // separate stream. |
| 5577 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5579 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5580 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5581 | } |
| 5582 | |
| 5583 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5584 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5585 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5586 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5587 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5588 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5589 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5590 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5591 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5592 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5593 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5594 | |
| 5595 | HttpRequestInfo request1; |
| 5596 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5597 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5598 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5599 | request1.traffic_annotation = |
| 5600 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5601 | |
| 5602 | HttpRequestInfo request2; |
| 5603 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5604 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5605 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5606 | request2.traffic_annotation = |
| 5607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5608 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5609 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5610 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5611 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5612 | spdy::SpdySerializedFrame conn_resp1( |
| 5613 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5614 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5615 | // Fetch https://www.example.org/ via HTTP. |
| 5616 | const char get1[] = |
| 5617 | "GET / HTTP/1.1\r\n" |
| 5618 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5619 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5620 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5621 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5622 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5623 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5624 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5625 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5626 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5627 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5628 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5629 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5630 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5631 | // Fetch https://www.example.org/2 via HTTP. |
| 5632 | const char get2[] = |
| 5633 | "GET /2 HTTP/1.1\r\n" |
| 5634 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5635 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5636 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5637 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5638 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5639 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5640 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5641 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5642 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5643 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5644 | |
| 5645 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5646 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5647 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5648 | }; |
| 5649 | |
| 5650 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5651 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5652 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5653 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5654 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5655 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5656 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5657 | }; |
| 5658 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5659 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5660 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5661 | |
| 5662 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5663 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5665 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5666 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5667 | |
| 5668 | TestCompletionCallback callback; |
| 5669 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5670 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5671 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5672 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5674 | |
| 5675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5676 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5677 | |
| 5678 | LoadTimingInfo load_timing_info; |
| 5679 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5680 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5681 | |
| 5682 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5683 | ASSERT_TRUE(response); |
| 5684 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5685 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5686 | |
| 5687 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5688 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5689 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5690 | trans.reset(); |
| 5691 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5692 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5693 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5694 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5696 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5697 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5698 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5699 | |
| 5700 | LoadTimingInfo load_timing_info2; |
| 5701 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5702 | TestLoadTimingReused(load_timing_info2); |
| 5703 | |
| 5704 | // The requests should have the same ID. |
| 5705 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5706 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5707 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5708 | } |
| 5709 | |
| 5710 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5711 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5712 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5713 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5714 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5715 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5716 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5717 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5718 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5719 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5720 | |
| 5721 | HttpRequestInfo request1; |
| 5722 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5723 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5724 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5725 | request1.traffic_annotation = |
| 5726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5727 | |
| 5728 | HttpRequestInfo request2; |
| 5729 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5730 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5731 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5732 | request2.traffic_annotation = |
| 5733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5734 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5735 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5736 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5737 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5738 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5739 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5740 | spdy::SpdySerializedFrame get_resp1( |
| 5741 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5742 | spdy::SpdySerializedFrame body1( |
| 5743 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5744 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5745 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5746 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5747 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5748 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5749 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5750 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 5751 | spdy::SpdySerializedFrame get_resp2( |
| 5752 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5753 | spdy::SpdySerializedFrame body2( |
| 5754 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5755 | |
| 5756 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5757 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5758 | }; |
| 5759 | |
| 5760 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5761 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5762 | CreateMockRead(body1, 2, ASYNC), |
| 5763 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5764 | CreateMockRead(body2, 5, ASYNC), |
| 5765 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5766 | }; |
| 5767 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5768 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5769 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5770 | |
| 5771 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5772 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5774 | |
| 5775 | TestCompletionCallback callback; |
| 5776 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5777 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5778 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5779 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5780 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5781 | |
| 5782 | LoadTimingInfo load_timing_info; |
| 5783 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5784 | TestLoadTimingNotReused(load_timing_info, |
| 5785 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5786 | |
| 5787 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5788 | ASSERT_TRUE(response); |
| 5789 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5790 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5791 | |
| 5792 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5793 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5794 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5795 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5796 | // Delete the first request, so the second one can reuse the socket. |
| 5797 | trans.reset(); |
| 5798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5799 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5800 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5801 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5802 | |
| 5803 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5804 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5805 | TestLoadTimingReused(load_timing_info2); |
| 5806 | |
| 5807 | // The requests should have the same ID. |
| 5808 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5810 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5811 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5812 | } |
| 5813 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5814 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5815 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5816 | HttpRequestInfo request; |
| 5817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5818 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5819 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5820 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5821 | request.traffic_annotation = |
| 5822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5823 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5824 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5825 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5826 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5827 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5828 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5830 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5831 | // Since we have proxy, should use full url |
| 5832 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5834 | "Host: www.example.org\r\n" |
| 5835 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5838 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5839 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5840 | "Host: www.example.org\r\n" |
| 5841 | "Proxy-Connection: keep-alive\r\n" |
| 5842 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5843 | }; |
| 5844 | |
| 5845 | // The proxy responds to the GET with a 407, using a persistent |
| 5846 | // connection. |
| 5847 | MockRead data_reads1[] = { |
| 5848 | // No credentials. |
| 5849 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5850 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5851 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5852 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5853 | |
| 5854 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5855 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5856 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5857 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5858 | }; |
| 5859 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5860 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5861 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5862 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5865 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5869 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5871 | |
| 5872 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5873 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5874 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5875 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5876 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5877 | TestLoadTimingNotReused(load_timing_info, |
| 5878 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5880 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5881 | ASSERT_TRUE(response); |
| 5882 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5883 | EXPECT_EQ(407, response->headers->response_code()); |
| 5884 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5885 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5887 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5889 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5891 | |
| 5892 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5894 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5895 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5896 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5897 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5898 | TestLoadTimingReused(load_timing_info); |
| 5899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5900 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5901 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5902 | |
| 5903 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5904 | EXPECT_EQ(200, response->headers->response_code()); |
| 5905 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5906 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5907 | |
| 5908 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5909 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5910 | } |
| 5911 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5912 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5913 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5914 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5916 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5917 | request.traffic_annotation = |
| 5918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5919 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5920 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5921 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5922 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5924 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5925 | // Since we have proxy, should try to establish tunnel. |
| 5926 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5927 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5928 | "Host: www.example.org:443\r\n" |
| 5929 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5930 | }; |
| 5931 | |
| 5932 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5933 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5934 | // No response body because the test stops reading here. |
| 5935 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5936 | }; |
| 5937 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5938 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5939 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5941 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5947 | |
| 5948 | rv = callback.WaitForResult(); |
| 5949 | EXPECT_EQ(expected_status, rv); |
| 5950 | } |
| 5951 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5952 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5953 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5954 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5955 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5956 | } |
| 5957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5959 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5960 | } |
| 5961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5963 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5964 | } |
| 5965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5967 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5968 | } |
| 5969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5971 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5972 | } |
| 5973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5974 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5975 | ConnectStatusHelper( |
| 5976 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5977 | } |
| 5978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5980 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5981 | } |
| 5982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5983 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5984 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5985 | } |
| 5986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5987 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5988 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5989 | } |
| 5990 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5991 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5992 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5993 | } |
| 5994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5995 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5996 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5997 | } |
| 5998 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5999 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6000 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6001 | } |
| 6002 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6003 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6004 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6005 | } |
| 6006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6007 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6008 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6009 | } |
| 6010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6011 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6012 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6013 | } |
| 6014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6015 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6016 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6017 | } |
| 6018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6019 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6020 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6021 | } |
| 6022 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6023 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6024 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6025 | } |
| 6026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6027 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6028 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6029 | } |
| 6030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6031 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6032 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6033 | } |
| 6034 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6035 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6036 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6037 | } |
| 6038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6039 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6040 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6041 | } |
| 6042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6043 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6044 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6045 | } |
| 6046 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6047 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6048 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6049 | } |
| 6050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6051 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6052 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6053 | } |
| 6054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6055 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6056 | ConnectStatusHelperWithExpectedStatus( |
| 6057 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6058 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6059 | } |
| 6060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6061 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6062 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6063 | } |
| 6064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6065 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6066 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6067 | } |
| 6068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6069 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6070 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6071 | } |
| 6072 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6073 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6074 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6075 | } |
| 6076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6077 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6078 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6079 | } |
| 6080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6081 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6082 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6083 | } |
| 6084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6085 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6086 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6087 | } |
| 6088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6089 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6090 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6091 | } |
| 6092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6093 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6094 | ConnectStatusHelper( |
| 6095 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6096 | } |
| 6097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6098 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6099 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6100 | } |
| 6101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6102 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6103 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6104 | } |
| 6105 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6106 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6107 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6108 | } |
| 6109 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6110 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6111 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6112 | } |
| 6113 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6114 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6115 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6116 | } |
| 6117 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6118 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6119 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6120 | } |
| 6121 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6122 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6123 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6124 | } |
| 6125 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6126 | // Test the flow when both the proxy server AND origin server require |
| 6127 | // authentication. Again, this uses basic auth for both since that is |
| 6128 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6129 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6130 | HttpRequestInfo request; |
| 6131 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6132 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6133 | request.traffic_annotation = |
| 6134 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6135 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6136 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6137 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6138 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6142 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6143 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6144 | MockWrite( |
| 6145 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6146 | "Host: www.example.org\r\n" |
| 6147 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6148 | }; |
| 6149 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6150 | MockRead data_reads1[] = { |
| 6151 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6152 | // Give a couple authenticate options (only the middle one is actually |
| 6153 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6154 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6155 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6156 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6157 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6158 | // Large content-length -- won't matter, as connection will be reset. |
| 6159 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6160 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6161 | }; |
| 6162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6163 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6164 | // request we should be issuing -- the final header line contains the |
| 6165 | // proxy's credentials. |
| 6166 | MockWrite data_writes2[] = { |
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" |
| 6171 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6172 | }; |
| 6173 | |
| 6174 | // Now the proxy server lets the request pass through to origin server. |
| 6175 | // The origin server responds with a 401. |
| 6176 | MockRead data_reads2[] = { |
| 6177 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6178 | // Note: We are using the same realm-name as the proxy server. This is |
| 6179 | // completely valid, as realms are unique across hosts. |
| 6180 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6181 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6182 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6183 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[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 second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6187 | // the credentials for both the proxy and origin server. |
| 6188 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6189 | MockWrite( |
| 6190 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6191 | "Host: www.example.org\r\n" |
| 6192 | "Proxy-Connection: keep-alive\r\n" |
| 6193 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6194 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6195 | }; |
| 6196 | |
| 6197 | // Lastly we get the desired content. |
| 6198 | MockRead data_reads3[] = { |
| 6199 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6200 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6201 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6202 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6203 | }; |
| 6204 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6205 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6206 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6207 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6209 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6210 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6212 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6213 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6214 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6215 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6216 | |
| 6217 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6218 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6221 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6222 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6223 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6224 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6226 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6228 | |
| 6229 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6232 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6233 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6234 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6236 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6238 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6239 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6241 | |
| 6242 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6243 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6245 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6246 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6247 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6248 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6249 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6250 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6251 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6252 | // authorization headers. |
| 6253 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6254 | // The NTLM authentication unit tests are based on known test data from the |
| 6255 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6256 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6257 | // for the implementation and testing of the protocol. |
| 6258 | // |
| 6259 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6260 | |
| 6261 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6262 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6263 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6264 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6265 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6266 | request.traffic_annotation = |
| 6267 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6268 | |
| 6269 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6270 | // to other auth schemes. |
| 6271 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6272 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6273 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6274 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6276 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6277 | // Generate the NTLM messages based on known test data. |
| 6278 | std::string negotiate_msg; |
| 6279 | std::string challenge_msg; |
| 6280 | std::string authenticate_msg; |
| 6281 | base::Base64Encode( |
| 6282 | base::StringPiece( |
| 6283 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6284 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6285 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6286 | base::Base64Encode( |
| 6287 | base::StringPiece( |
| 6288 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6289 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6290 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6291 | base::Base64Encode( |
| 6292 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6293 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6294 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6295 | arraysize( |
| 6296 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6297 | &authenticate_msg); |
| 6298 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6299 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6300 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6301 | "Host: server\r\n" |
| 6302 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6303 | }; |
| 6304 | |
| 6305 | MockRead data_reads1[] = { |
| 6306 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6307 | // Negotiate and NTLM are often requested together. However, we only want |
| 6308 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6309 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6310 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6311 | MockRead("Connection: close\r\n"), |
| 6312 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6313 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6314 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6315 | }; |
| 6316 | |
| 6317 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6318 | // After restarting with a null identity, this is the |
| 6319 | // request we should be issuing -- the final header line contains a Type |
| 6320 | // 1 message. |
| 6321 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6322 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6323 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6324 | "Authorization: NTLM "), |
| 6325 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6327 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6328 | // (using correct credentials). The second request continues on the |
| 6329 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6330 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6331 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6332 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6333 | "Authorization: NTLM "), |
| 6334 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6335 | }; |
| 6336 | |
| 6337 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6338 | // The origin server responds with a Type 2 message. |
| 6339 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6340 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6341 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6342 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6343 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6344 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6345 | // Lastly we get the desired content. |
| 6346 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6347 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6348 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6349 | }; |
| 6350 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6351 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6352 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6353 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6354 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6355 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6356 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6358 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6360 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6361 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6365 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6367 | |
| 6368 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6371 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6374 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6375 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6377 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6378 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6379 | rv = trans.RestartWithAuth( |
| 6380 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6381 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6383 | |
| 6384 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6387 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6389 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6390 | ASSERT_TRUE(response); |
| 6391 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6393 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6397 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6398 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6399 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6401 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6402 | ASSERT_TRUE(response); |
| 6403 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6404 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6405 | |
| 6406 | std::string response_data; |
| 6407 | rv = ReadTransaction(&trans, &response_data); |
| 6408 | EXPECT_THAT(rv, IsOk()); |
| 6409 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6410 | |
| 6411 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6412 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6413 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6414 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6415 | } |
| 6416 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6417 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6418 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6419 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6420 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6421 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6422 | request.traffic_annotation = |
| 6423 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6424 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6425 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6426 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6428 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6429 | // Generate the NTLM messages based on known test data. |
| 6430 | std::string negotiate_msg; |
| 6431 | std::string challenge_msg; |
| 6432 | std::string authenticate_msg; |
| 6433 | base::Base64Encode( |
| 6434 | base::StringPiece( |
| 6435 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6436 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6437 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6438 | base::Base64Encode( |
| 6439 | base::StringPiece( |
| 6440 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6441 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6442 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6443 | base::Base64Encode( |
| 6444 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6445 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6446 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6447 | arraysize( |
| 6448 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6449 | &authenticate_msg); |
| 6450 | |
| 6451 | // The authenticate message when |kWrongPassword| is sent. |
| 6452 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6453 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6454 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6455 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6456 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6457 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6458 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6459 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6460 | // Sanity check that it's the same length as the correct authenticate message |
| 6461 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6462 | ASSERT_EQ(authenticate_msg.length(), |
| 6463 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6464 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6465 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6466 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6467 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6468 | "Host: server\r\n" |
| 6469 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6470 | }; |
| 6471 | |
| 6472 | MockRead data_reads1[] = { |
| 6473 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6474 | // Negotiate and NTLM are often requested together. However, we only want |
| 6475 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6476 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6477 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6478 | MockRead("Connection: close\r\n"), |
| 6479 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6480 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6481 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6482 | }; |
| 6483 | |
| 6484 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6485 | // After restarting with a null identity, this is the |
| 6486 | // request we should be issuing -- the final header line contains a Type |
| 6487 | // 1 message. |
| 6488 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6489 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6490 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6491 | "Authorization: NTLM "), |
| 6492 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6494 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6495 | // (using incorrect credentials). The second request continues on the |
| 6496 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6497 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6498 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6499 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6500 | "Authorization: NTLM "), |
| 6501 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6502 | }; |
| 6503 | |
| 6504 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6505 | // The origin server responds with a Type 2 message. |
| 6506 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6507 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6508 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6509 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6510 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6511 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6512 | // Wrong password. |
| 6513 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6514 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6515 | MockRead("Content-Length: 42\r\n"), |
| 6516 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6517 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6518 | }; |
| 6519 | |
| 6520 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6521 | // After restarting with a null identity, this is the |
| 6522 | // request we should be issuing -- the final header line contains a Type |
| 6523 | // 1 message. |
| 6524 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6525 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6526 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6527 | "Authorization: NTLM "), |
| 6528 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6530 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6531 | // (the credentials for the origin server). The second request continues |
| 6532 | // on the same connection. |
| 6533 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6534 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6535 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6536 | "Authorization: NTLM "), |
| 6537 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6538 | }; |
| 6539 | |
| 6540 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6541 | // The origin server responds with a Type 2 message. |
| 6542 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6543 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6544 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6545 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6546 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6547 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6548 | // Lastly we get the desired content. |
| 6549 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6550 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6551 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6552 | }; |
| 6553 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6554 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6555 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6556 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6557 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6558 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6559 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6560 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6561 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6563 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6565 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6568 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6571 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6572 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6573 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6574 | |
| 6575 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6576 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6578 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6580 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6581 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6582 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6584 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6585 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6586 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6587 | rv = trans.RestartWithAuth( |
| 6588 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6589 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6591 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6592 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6595 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6596 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6597 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6599 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6600 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6601 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6603 | 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] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6607 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6608 | |
| 6609 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6610 | rv = trans.RestartWithAuth( |
| 6611 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6612 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6614 | |
| 6615 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6618 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6620 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6621 | |
| 6622 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6623 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6625 | |
| 6626 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6629 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6630 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6631 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6632 | |
| 6633 | std::string response_data; |
| 6634 | rv = ReadTransaction(&trans, &response_data); |
| 6635 | EXPECT_THAT(rv, IsOk()); |
| 6636 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6637 | |
| 6638 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6639 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6640 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6641 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6642 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6643 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6644 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6645 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6646 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6647 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6648 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6649 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6650 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6651 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6652 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6653 | |
| 6654 | HttpRequestInfo request; |
| 6655 | request.method = "GET"; |
| 6656 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6657 | request.traffic_annotation = |
| 6658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6659 | |
| 6660 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6661 | spdy::SpdyHeaderBlock request_headers0( |
| 6662 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6663 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6664 | 1, std::move(request_headers0), LOWEST, true)); |
| 6665 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6666 | spdy::SpdyHeaderBlock response_headers0; |
| 6667 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6668 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6669 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6670 | 1, std::move(response_headers0), true)); |
| 6671 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6672 | // Stream 1 is closed. |
| 6673 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6674 | |
| 6675 | // Generate the NTLM messages based on known test data. |
| 6676 | std::string negotiate_msg; |
| 6677 | std::string challenge_msg; |
| 6678 | std::string authenticate_msg; |
| 6679 | base::Base64Encode( |
| 6680 | base::StringPiece( |
| 6681 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6682 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6683 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6684 | base::Base64Encode( |
| 6685 | base::StringPiece( |
| 6686 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6687 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6688 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6689 | base::Base64Encode( |
| 6690 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6691 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6692 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6693 | arraysize( |
| 6694 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6695 | &authenticate_msg); |
| 6696 | |
| 6697 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6698 | spdy::SpdyHeaderBlock request_headers1( |
| 6699 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6700 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6701 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6702 | 3, std::move(request_headers1), LOWEST, true)); |
| 6703 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 6704 | spdy::SpdySerializedFrame rst( |
| 6705 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6706 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6707 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6708 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6709 | |
| 6710 | // Retry yet again using HTTP/1.1. |
| 6711 | MockWrite writes1[] = { |
| 6712 | // After restarting with a null identity, this is the |
| 6713 | // request we should be issuing -- the final header line contains a Type |
| 6714 | // 1 message. |
| 6715 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6716 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6717 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6718 | "Authorization: NTLM "), |
| 6719 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6720 | |
| 6721 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6722 | // (the credentials for the origin server). The second request continues |
| 6723 | // on the same connection. |
| 6724 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6725 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6726 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6727 | "Authorization: NTLM "), |
| 6728 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6729 | }; |
| 6730 | |
| 6731 | MockRead reads1[] = { |
| 6732 | // The origin server responds with a Type 2 message. |
| 6733 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6734 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6735 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6736 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6737 | MockRead("You are not authorized to view this page\r\n"), |
| 6738 | |
| 6739 | // Lastly we get the desired content. |
| 6740 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6741 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6742 | 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] | 6743 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6744 | SequencedSocketData data0(reads0, writes0); |
| 6745 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6746 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6747 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6748 | |
| 6749 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6750 | ssl0.next_proto = kProtoHTTP2; |
| 6751 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6754 | |
| 6755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6757 | |
| 6758 | TestCompletionCallback callback1; |
| 6759 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6761 | |
| 6762 | rv = callback1.WaitForResult(); |
| 6763 | EXPECT_THAT(rv, IsOk()); |
| 6764 | |
| 6765 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6766 | |
| 6767 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6768 | ASSERT_TRUE(response); |
| 6769 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6770 | |
| 6771 | TestCompletionCallback callback2; |
| 6772 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6773 | rv = trans.RestartWithAuth( |
| 6774 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6775 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6777 | |
| 6778 | rv = callback2.WaitForResult(); |
| 6779 | EXPECT_THAT(rv, IsOk()); |
| 6780 | |
| 6781 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6782 | |
| 6783 | response = trans.GetResponseInfo(); |
| 6784 | ASSERT_TRUE(response); |
| 6785 | EXPECT_FALSE(response->auth_challenge); |
| 6786 | |
| 6787 | TestCompletionCallback callback3; |
| 6788 | |
| 6789 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6791 | |
| 6792 | rv = callback3.WaitForResult(); |
| 6793 | EXPECT_THAT(rv, IsOk()); |
| 6794 | |
| 6795 | response = trans.GetResponseInfo(); |
| 6796 | ASSERT_TRUE(response); |
| 6797 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6798 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6799 | |
| 6800 | std::string response_data; |
| 6801 | rv = ReadTransaction(&trans, &response_data); |
| 6802 | EXPECT_THAT(rv, IsOk()); |
| 6803 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6804 | |
| 6805 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6806 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6807 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6808 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6809 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6810 | |
| 6811 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 6812 | // do no retry forever checking for TLS version interference. This is a |
| 6813 | // regression test for https://crbug.com/823387. |
| 6814 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 6815 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 6816 | // https://origin/. |
| 6817 | session_deps_.proxy_resolution_service = |
| 6818 | ProxyResolutionService::CreateFixedFromPacResult( |
| 6819 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6820 | |
| 6821 | SSLConfig config; |
| 6822 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 6823 | session_deps_.ssl_config_service = |
| 6824 | base::MakeRefCounted<TestSSLConfigService>(config); |
| 6825 | |
| 6826 | HttpRequestInfo request; |
| 6827 | request.method = "GET"; |
| 6828 | request.url = GURL("https://origin/"); |
| 6829 | request.traffic_annotation = |
| 6830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6831 | |
| 6832 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6833 | // to other auth schemes. |
| 6834 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6835 | |
| 6836 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6837 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 6838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6839 | |
| 6840 | // Generate the NTLM messages based on known test data. |
| 6841 | std::string negotiate_msg; |
| 6842 | std::string challenge_msg; |
| 6843 | std::string authenticate_msg; |
| 6844 | base::Base64Encode( |
| 6845 | base::StringPiece( |
| 6846 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6847 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6848 | &negotiate_msg); |
| 6849 | base::Base64Encode( |
| 6850 | base::StringPiece( |
| 6851 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6852 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6853 | &challenge_msg); |
| 6854 | base::Base64Encode( |
| 6855 | base::StringPiece( |
| 6856 | reinterpret_cast<const char*>( |
| 6857 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6858 | arraysize( |
| 6859 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 6860 | &authenticate_msg); |
| 6861 | |
| 6862 | MockWrite data_writes[] = { |
| 6863 | // The initial CONNECT request. |
| 6864 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6865 | "Host: origin:443\r\n" |
| 6866 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6867 | |
| 6868 | // After restarting with an identity. |
| 6869 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6870 | "Host: origin:443\r\n" |
| 6871 | "Proxy-Connection: keep-alive\r\n" |
| 6872 | "Proxy-Authorization: NTLM "), |
| 6873 | MockWrite(negotiate_msg.c_str()), |
| 6874 | // End headers. |
| 6875 | MockWrite("\r\n\r\n"), |
| 6876 | |
| 6877 | // The second restart. |
| 6878 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6879 | "Host: origin:443\r\n" |
| 6880 | "Proxy-Connection: keep-alive\r\n" |
| 6881 | "Proxy-Authorization: NTLM "), |
| 6882 | MockWrite(authenticate_msg.c_str()), |
| 6883 | // End headers. |
| 6884 | MockWrite("\r\n\r\n"), |
| 6885 | }; |
| 6886 | |
| 6887 | MockRead data_reads[] = { |
| 6888 | // The initial NTLM response. |
| 6889 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6890 | "Content-Length: 0\r\n" |
| 6891 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 6892 | |
| 6893 | // The NTLM challenge message. |
| 6894 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6895 | "Content-Length: 0\r\n" |
| 6896 | "Proxy-Authenticate: NTLM "), |
| 6897 | MockRead(challenge_msg.c_str()), |
| 6898 | // End headers. |
| 6899 | MockRead("\r\n\r\n"), |
| 6900 | |
| 6901 | // Finally the tunnel is established. |
| 6902 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 6903 | }; |
| 6904 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6905 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6906 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6907 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6908 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
| 6909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 6911 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 6913 | |
| 6914 | // Start the transaction. The proxy responds with an NTLM authentication |
| 6915 | // request. |
| 6916 | TestCompletionCallback callback; |
| 6917 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6918 | int rv = callback.GetResult( |
| 6919 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 6920 | |
| 6921 | EXPECT_THAT(rv, IsOk()); |
| 6922 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6924 | ASSERT_TRUE(response); |
| 6925 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 6926 | |
| 6927 | // Configure credentials. The proxy responds with the challenge message. |
| 6928 | rv = callback.GetResult(trans.RestartWithAuth( |
| 6929 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6930 | callback.callback())); |
| 6931 | EXPECT_THAT(rv, IsOk()); |
| 6932 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6933 | response = trans.GetResponseInfo(); |
| 6934 | ASSERT_TRUE(response); |
| 6935 | EXPECT_FALSE(response->auth_challenge); |
| 6936 | |
| 6937 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 6938 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 6939 | // restart the process. The proxy responds with another NTLM authentiation |
| 6940 | // request, but we don't need to provide credentials as the cached ones work/ |
| 6941 | rv = callback.GetResult( |
| 6942 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6943 | EXPECT_THAT(rv, IsOk()); |
| 6944 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6945 | response = trans.GetResponseInfo(); |
| 6946 | ASSERT_TRUE(response); |
| 6947 | EXPECT_FALSE(response->auth_challenge); |
| 6948 | |
| 6949 | // The proxy responds with the NTLM challenge message. |
| 6950 | rv = callback.GetResult( |
| 6951 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6952 | EXPECT_THAT(rv, IsOk()); |
| 6953 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6954 | response = trans.GetResponseInfo(); |
| 6955 | ASSERT_TRUE(response); |
| 6956 | EXPECT_FALSE(response->auth_challenge); |
| 6957 | |
| 6958 | // Send the NTLM authenticate message. The tunnel is established and the |
| 6959 | // handshake resets again. We should not retry again. |
| 6960 | rv = callback.GetResult( |
| 6961 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6962 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 6963 | } |
| 6964 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6965 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6966 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6967 | // Test reading a server response which has only headers, and no body. |
| 6968 | // After some maximum number of bytes is consumed, the transaction should |
| 6969 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6970 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6971 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6972 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6973 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6974 | request.traffic_annotation = |
| 6975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6979 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6980 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6981 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6982 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6983 | |
| 6984 | MockRead data_reads[] = { |
| 6985 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6986 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6987 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6989 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6990 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6991 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6993 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6995 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6997 | |
| 6998 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6999 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7000 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7001 | |
| 7002 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7003 | // establish tunnel. |
| 7004 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7005 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7006 | HttpRequestInfo request; |
| 7007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7008 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7009 | request.traffic_annotation = |
| 7010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7011 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7012 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7013 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7014 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7015 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7017 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7018 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7019 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7020 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7021 | // Since we have proxy, should try to establish tunnel. |
| 7022 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7023 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7024 | "Host: www.example.org:443\r\n" |
| 7025 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7026 | }; |
| 7027 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7028 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7029 | // connection. Usually a proxy would return 501 (not implemented), |
| 7030 | // or 200 (tunnel established). |
| 7031 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7032 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7033 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7034 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7035 | }; |
| 7036 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7037 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7038 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7040 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7041 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7042 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7044 | |
| 7045 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7046 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7047 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7048 | // Empty the current queue. This is necessary because idle sockets are |
| 7049 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7050 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7051 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7052 | // We now check to make sure the TCPClientSocket was not added back to |
| 7053 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7054 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7055 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7056 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7057 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7058 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7059 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7060 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7061 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7062 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7063 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7064 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7065 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7066 | request.traffic_annotation = |
| 7067 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7072 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7073 | MockRead data_reads[] = { |
| 7074 | // A part of the response body is received with the response headers. |
| 7075 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7076 | // The rest of the response body is received in two parts. |
| 7077 | MockRead("lo"), |
| 7078 | MockRead(" world"), |
| 7079 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7080 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7081 | }; |
| 7082 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7083 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7084 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7086 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7088 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7090 | |
| 7091 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7092 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7094 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7095 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7096 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7097 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7098 | std::string status_line = response->headers->GetStatusLine(); |
| 7099 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7100 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7101 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7102 | |
| 7103 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7104 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7105 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7106 | EXPECT_EQ("hello world", response_data); |
| 7107 | |
| 7108 | // Empty the current queue. This is necessary because idle sockets are |
| 7109 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7110 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7111 | |
| 7112 | // 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] | 7113 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7114 | } |
| 7115 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7116 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7117 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7118 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7119 | HttpRequestInfo request; |
| 7120 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7121 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7122 | request.traffic_annotation = |
| 7123 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7124 | |
| 7125 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7126 | MockWrite( |
| 7127 | "GET / HTTP/1.1\r\n" |
| 7128 | "Host: www.example.org\r\n" |
| 7129 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7130 | }; |
| 7131 | |
| 7132 | MockRead data_reads[] = { |
| 7133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7134 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7135 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7136 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7137 | }; |
| 7138 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7139 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7141 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7142 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7145 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7146 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7147 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7148 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7150 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7151 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7153 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7155 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7156 | ASSERT_TRUE(response); |
| 7157 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7158 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7159 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7160 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7161 | |
| 7162 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7163 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7165 | EXPECT_EQ("hello world", response_data); |
| 7166 | |
| 7167 | // Empty the current queue. This is necessary because idle sockets are |
| 7168 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7169 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7170 | |
| 7171 | // 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] | 7172 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7173 | } |
| 7174 | |
| 7175 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7176 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7177 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7178 | HttpRequestInfo request; |
| 7179 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7180 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7181 | request.traffic_annotation = |
| 7182 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7183 | |
| 7184 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7185 | MockWrite( |
| 7186 | "GET / HTTP/1.1\r\n" |
| 7187 | "Host: www.example.org\r\n" |
| 7188 | "Connection: keep-alive\r\n\r\n"), |
| 7189 | MockWrite( |
| 7190 | "GET / HTTP/1.1\r\n" |
| 7191 | "Host: www.example.org\r\n" |
| 7192 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7193 | }; |
| 7194 | |
| 7195 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7196 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7197 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7198 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7199 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7200 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7203 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7204 | StaticSocketDataProvider data(data_reads, data_writes); |
| 7205 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7206 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7207 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7209 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7212 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7213 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7214 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7215 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7216 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7218 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7219 | |
| 7220 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7221 | ASSERT_TRUE(response); |
| 7222 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7223 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7224 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7225 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7226 | |
| 7227 | std::string response_data; |
| 7228 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7229 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7230 | EXPECT_EQ("hello world", response_data); |
| 7231 | |
| 7232 | // Empty the current queue. This is necessary because idle sockets are |
| 7233 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7234 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7235 | |
| 7236 | // 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] | 7237 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7238 | |
| 7239 | // Now start the second transaction, which should reuse the previous socket. |
| 7240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7241 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7242 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7244 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7245 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7247 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7248 | |
| 7249 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7250 | ASSERT_TRUE(response); |
| 7251 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7252 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7253 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7254 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7255 | |
| 7256 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7257 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7258 | EXPECT_EQ("hello world", response_data); |
| 7259 | |
| 7260 | // Empty the current queue. This is necessary because idle sockets are |
| 7261 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7262 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7263 | |
| 7264 | // 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] | 7265 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7266 | } |
| 7267 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7268 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7269 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7270 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7271 | HttpRequestInfo request; |
| 7272 | request.method = "GET"; |
| 7273 | request.url = GURL("http://www.example.org/"); |
| 7274 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7275 | request.traffic_annotation = |
| 7276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7277 | |
| 7278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7281 | |
| 7282 | MockRead data_reads[] = { |
| 7283 | // A part of the response body is received with the response headers. |
| 7284 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7285 | // The rest of the response body is received in two parts. |
| 7286 | MockRead("lo"), MockRead(" world"), |
| 7287 | MockRead("junk"), // Should not be read!! |
| 7288 | MockRead(SYNCHRONOUS, OK), |
| 7289 | }; |
| 7290 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7291 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7293 | |
| 7294 | TestCompletionCallback callback; |
| 7295 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7298 | |
| 7299 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7301 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7302 | ASSERT_TRUE(response); |
| 7303 | EXPECT_TRUE(response->headers); |
| 7304 | std::string status_line = response->headers->GetStatusLine(); |
| 7305 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7306 | |
| 7307 | // Make memory critical notification and ensure the transaction still has been |
| 7308 | // operating right. |
| 7309 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7310 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7311 | base::RunLoop().RunUntilIdle(); |
| 7312 | |
| 7313 | // Socket should not be flushed as long as it is not idle. |
| 7314 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7315 | |
| 7316 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7317 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7318 | EXPECT_THAT(rv, IsOk()); |
| 7319 | EXPECT_EQ("hello world", response_data); |
| 7320 | |
| 7321 | // Empty the current queue. This is necessary because idle sockets are |
| 7322 | // added to the connection pool asynchronously with a PostTask. |
| 7323 | base::RunLoop().RunUntilIdle(); |
| 7324 | |
| 7325 | // We now check to make sure the socket was added back to the pool. |
| 7326 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7327 | |
| 7328 | // Idle sockets should be flushed now. |
| 7329 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7330 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7331 | base::RunLoop().RunUntilIdle(); |
| 7332 | |
| 7333 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7334 | } |
| 7335 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7336 | // Disable idle socket closing on memory pressure. |
| 7337 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7338 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7339 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7340 | HttpRequestInfo request; |
| 7341 | request.method = "GET"; |
| 7342 | request.url = GURL("http://www.example.org/"); |
| 7343 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7344 | request.traffic_annotation = |
| 7345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7346 | |
| 7347 | // Disable idle socket closing on memory pressure. |
| 7348 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7349 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7350 | |
| 7351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7352 | |
| 7353 | MockRead data_reads[] = { |
| 7354 | // A part of the response body is received with the response headers. |
| 7355 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7356 | // The rest of the response body is received in two parts. |
| 7357 | MockRead("lo"), MockRead(" world"), |
| 7358 | MockRead("junk"), // Should not be read!! |
| 7359 | MockRead(SYNCHRONOUS, OK), |
| 7360 | }; |
| 7361 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7362 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7364 | |
| 7365 | TestCompletionCallback callback; |
| 7366 | |
| 7367 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7369 | |
| 7370 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7371 | |
| 7372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7373 | ASSERT_TRUE(response); |
| 7374 | EXPECT_TRUE(response->headers); |
| 7375 | std::string status_line = response->headers->GetStatusLine(); |
| 7376 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7377 | |
| 7378 | // Make memory critical notification and ensure the transaction still has been |
| 7379 | // operating right. |
| 7380 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7381 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7382 | base::RunLoop().RunUntilIdle(); |
| 7383 | |
| 7384 | // Socket should not be flushed as long as it is not idle. |
| 7385 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7386 | |
| 7387 | std::string response_data; |
| 7388 | rv = ReadTransaction(&trans, &response_data); |
| 7389 | EXPECT_THAT(rv, IsOk()); |
| 7390 | EXPECT_EQ("hello world", response_data); |
| 7391 | |
| 7392 | // Empty the current queue. This is necessary because idle sockets are |
| 7393 | // added to the connection pool asynchronously with a PostTask. |
| 7394 | base::RunLoop().RunUntilIdle(); |
| 7395 | |
| 7396 | // We now check to make sure the socket was added back to the pool. |
| 7397 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7398 | |
| 7399 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7400 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7401 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7402 | base::RunLoop().RunUntilIdle(); |
| 7403 | |
| 7404 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7405 | |
| 7406 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7407 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7408 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7409 | base::RunLoop().RunUntilIdle(); |
| 7410 | |
| 7411 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7412 | } |
| 7413 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7414 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7415 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7416 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7417 | HttpRequestInfo request; |
| 7418 | request.method = "GET"; |
| 7419 | request.url = GURL("https://www.example.org/"); |
| 7420 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7421 | request.traffic_annotation = |
| 7422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7423 | |
| 7424 | MockWrite data_writes[] = { |
| 7425 | MockWrite("GET / HTTP/1.1\r\n" |
| 7426 | "Host: www.example.org\r\n" |
| 7427 | "Connection: keep-alive\r\n\r\n"), |
| 7428 | }; |
| 7429 | |
| 7430 | MockRead data_reads[] = { |
| 7431 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7432 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7433 | |
| 7434 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7436 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7437 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7439 | |
| 7440 | TestCompletionCallback callback; |
| 7441 | |
| 7442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7444 | |
| 7445 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7446 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7447 | |
| 7448 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7449 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7450 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7451 | ASSERT_TRUE(response); |
| 7452 | ASSERT_TRUE(response->headers); |
| 7453 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7454 | |
| 7455 | // Make memory critical notification and ensure the transaction still has been |
| 7456 | // operating right. |
| 7457 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7458 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7459 | base::RunLoop().RunUntilIdle(); |
| 7460 | |
| 7461 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7462 | |
| 7463 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7464 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7465 | EXPECT_THAT(rv, IsOk()); |
| 7466 | EXPECT_EQ("hello world", response_data); |
| 7467 | |
| 7468 | // Empty the current queue. This is necessary because idle sockets are |
| 7469 | // added to the connection pool asynchronously with a PostTask. |
| 7470 | base::RunLoop().RunUntilIdle(); |
| 7471 | |
| 7472 | // We now check to make sure the socket was added back to the pool. |
| 7473 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7474 | |
| 7475 | // Make memory notification once again and ensure idle socket is closed. |
| 7476 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7477 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7478 | base::RunLoop().RunUntilIdle(); |
| 7479 | |
| 7480 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7481 | } |
| 7482 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7483 | // Make sure that we recycle a socket after a zero-length response. |
| 7484 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7485 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7486 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7488 | request.url = GURL( |
| 7489 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7490 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7491 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7492 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7493 | request.traffic_annotation = |
| 7494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7495 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7497 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7498 | MockRead data_reads[] = { |
| 7499 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7500 | "Content-Length: 0\r\n" |
| 7501 | "Content-Type: text/html\r\n\r\n"), |
| 7502 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7503 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7504 | }; |
| 7505 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7506 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7507 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7508 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7509 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7510 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7511 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7513 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7517 | |
| 7518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7519 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7520 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7521 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7522 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7523 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7524 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7525 | std::string status_line = response->headers->GetStatusLine(); |
| 7526 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7527 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7528 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7529 | |
| 7530 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7531 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7532 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7533 | EXPECT_EQ("", response_data); |
| 7534 | |
| 7535 | // Empty the current queue. This is necessary because idle sockets are |
| 7536 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7537 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7538 | |
| 7539 | // 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] | 7540 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7541 | } |
| 7542 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7543 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7544 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7545 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7546 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7547 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7548 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7549 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7550 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7551 | // after use. |
| 7552 | request[0].method = "GET"; |
| 7553 | request[0].url = GURL("http://www.google.com/"); |
| 7554 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7555 | request[0].traffic_annotation = |
| 7556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7557 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7558 | // transaction 1. The first attempts fails when writing the POST data. |
| 7559 | // This causes the transaction to retry with a new socket. The second |
| 7560 | // attempt succeeds. |
| 7561 | request[1].method = "POST"; |
| 7562 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7563 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7564 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7565 | request[1].traffic_annotation = |
| 7566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7569 | |
| 7570 | // The first socket is used for transaction 1 and the first attempt of |
| 7571 | // transaction 2. |
| 7572 | |
| 7573 | // The response of transaction 1. |
| 7574 | MockRead data_reads1[] = { |
| 7575 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7576 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7578 | }; |
| 7579 | // The mock write results of transaction 1 and the first attempt of |
| 7580 | // transaction 2. |
| 7581 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7582 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7583 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7584 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7585 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7586 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7587 | |
| 7588 | // The second socket is used for the second attempt of transaction 2. |
| 7589 | |
| 7590 | // The response of transaction 2. |
| 7591 | MockRead data_reads2[] = { |
| 7592 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7593 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7594 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7595 | }; |
| 7596 | // The mock write results of the second attempt of transaction 2. |
| 7597 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7598 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7599 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7601 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7602 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7603 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7604 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7605 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7606 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7607 | "hello world", "welcome" |
| 7608 | }; |
| 7609 | |
| 7610 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7613 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7615 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7617 | |
| 7618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7619 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7620 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7621 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7622 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7623 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7624 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7625 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7626 | |
| 7627 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7628 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7629 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7630 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7631 | } |
| 7632 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7633 | |
| 7634 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7635 | // 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] | 7636 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7637 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7638 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7640 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7641 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7642 | request.traffic_annotation = |
| 7643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7647 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7648 | // The password contains an escaped character -- for this test to pass it |
| 7649 | // will need to be unescaped by HttpNetworkTransaction. |
| 7650 | EXPECT_EQ("b%40r", request.url.password()); |
| 7651 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7652 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7653 | MockWrite( |
| 7654 | "GET / HTTP/1.1\r\n" |
| 7655 | "Host: www.example.org\r\n" |
| 7656 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7657 | }; |
| 7658 | |
| 7659 | MockRead data_reads1[] = { |
| 7660 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7661 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7662 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7663 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7664 | }; |
| 7665 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7666 | // After the challenge above, the transaction will be restarted using the |
| 7667 | // identity from the url (foo, b@r) to answer the challenge. |
| 7668 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7669 | MockWrite( |
| 7670 | "GET / HTTP/1.1\r\n" |
| 7671 | "Host: www.example.org\r\n" |
| 7672 | "Connection: keep-alive\r\n" |
| 7673 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7674 | }; |
| 7675 | |
| 7676 | MockRead data_reads2[] = { |
| 7677 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7678 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7679 | MockRead(SYNCHRONOUS, OK), |
| 7680 | }; |
| 7681 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7682 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7683 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7685 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7686 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7687 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7688 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7690 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7691 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7692 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7693 | |
| 7694 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7695 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7697 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7698 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7699 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7701 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7702 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7703 | |
| 7704 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7705 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7706 | |
| 7707 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7708 | |
| 7709 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7710 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7711 | } |
| 7712 | |
| 7713 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7714 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7715 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7716 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7717 | HttpRequestInfo request; |
| 7718 | request.method = "GET"; |
| 7719 | // Note: the URL has a username:password in it. The password "baz" is |
| 7720 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7721 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7722 | |
| 7723 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7724 | request.traffic_annotation = |
| 7725 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7729 | |
| 7730 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7731 | MockWrite( |
| 7732 | "GET / HTTP/1.1\r\n" |
| 7733 | "Host: www.example.org\r\n" |
| 7734 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7735 | }; |
| 7736 | |
| 7737 | MockRead data_reads1[] = { |
| 7738 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7739 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7740 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7741 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7742 | }; |
| 7743 | |
| 7744 | // After the challenge above, the transaction will be restarted using the |
| 7745 | // identity from the url (foo, baz) to answer the challenge. |
| 7746 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7747 | MockWrite( |
| 7748 | "GET / HTTP/1.1\r\n" |
| 7749 | "Host: www.example.org\r\n" |
| 7750 | "Connection: keep-alive\r\n" |
| 7751 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7752 | }; |
| 7753 | |
| 7754 | MockRead data_reads2[] = { |
| 7755 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7756 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7757 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7758 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7759 | }; |
| 7760 | |
| 7761 | // After the challenge above, the transaction will be restarted using the |
| 7762 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7763 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7764 | MockWrite( |
| 7765 | "GET / HTTP/1.1\r\n" |
| 7766 | "Host: www.example.org\r\n" |
| 7767 | "Connection: keep-alive\r\n" |
| 7768 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7769 | }; |
| 7770 | |
| 7771 | MockRead data_reads3[] = { |
| 7772 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7773 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7774 | MockRead(SYNCHRONOUS, OK), |
| 7775 | }; |
| 7776 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7777 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7778 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7779 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7780 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7781 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7782 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7783 | |
| 7784 | TestCompletionCallback callback1; |
| 7785 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7786 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7788 | |
| 7789 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7790 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7792 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7793 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7794 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7796 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7797 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7798 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7800 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7801 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7802 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7803 | |
| 7804 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7805 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7807 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7808 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7809 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7811 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7812 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7813 | |
| 7814 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7815 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7816 | |
| 7817 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7818 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7819 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7820 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7821 | } |
| 7822 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7823 | |
| 7824 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7825 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7826 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7827 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7828 | HttpRequestInfo request; |
| 7829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7830 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7831 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7832 | request.traffic_annotation = |
| 7833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7834 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7835 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7837 | |
| 7838 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7839 | MockWrite( |
| 7840 | "GET / HTTP/1.1\r\n" |
| 7841 | "Host: www.example.org\r\n" |
| 7842 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7843 | }; |
| 7844 | |
| 7845 | MockRead data_reads1[] = { |
| 7846 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7847 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7848 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7849 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7850 | }; |
| 7851 | |
| 7852 | // After the challenge above, the transaction will be restarted using the |
| 7853 | // identity supplied by the user, not the one in the URL, to answer the |
| 7854 | // challenge. |
| 7855 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7856 | MockWrite( |
| 7857 | "GET / HTTP/1.1\r\n" |
| 7858 | "Host: www.example.org\r\n" |
| 7859 | "Connection: keep-alive\r\n" |
| 7860 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7861 | }; |
| 7862 | |
| 7863 | MockRead data_reads3[] = { |
| 7864 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7865 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7866 | MockRead(SYNCHRONOUS, OK), |
| 7867 | }; |
| 7868 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7869 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7870 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7871 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7872 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7873 | |
| 7874 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7875 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7877 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7878 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7879 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7881 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7882 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7883 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7884 | |
| 7885 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7886 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7888 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7889 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7890 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7892 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7893 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7894 | |
| 7895 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7896 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7897 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7898 | |
| 7899 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7900 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7901 | } |
| 7902 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7903 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7904 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7905 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7906 | |
| 7907 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7908 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7909 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7911 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7912 | request.traffic_annotation = |
| 7913 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7916 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7917 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7918 | MockWrite( |
| 7919 | "GET /x/y/z HTTP/1.1\r\n" |
| 7920 | "Host: www.example.org\r\n" |
| 7921 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7922 | }; |
| 7923 | |
| 7924 | MockRead data_reads1[] = { |
| 7925 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7926 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7927 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7928 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7929 | }; |
| 7930 | |
| 7931 | // Resend with authorization (username=foo, password=bar) |
| 7932 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7933 | MockWrite( |
| 7934 | "GET /x/y/z HTTP/1.1\r\n" |
| 7935 | "Host: www.example.org\r\n" |
| 7936 | "Connection: keep-alive\r\n" |
| 7937 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7938 | }; |
| 7939 | |
| 7940 | // Sever accepts the authorization. |
| 7941 | MockRead data_reads2[] = { |
| 7942 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7943 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7944 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7945 | }; |
| 7946 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7947 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7948 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7949 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7950 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7951 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7952 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7953 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7954 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7956 | |
| 7957 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7960 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7961 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7962 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7964 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7966 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7967 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7969 | |
| 7970 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7971 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7972 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7973 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7974 | ASSERT_TRUE(response); |
| 7975 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7976 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7977 | } |
| 7978 | |
| 7979 | // ------------------------------------------------------------------------ |
| 7980 | |
| 7981 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7982 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7983 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7984 | request.method = "GET"; |
| 7985 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7986 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7987 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7988 | request.traffic_annotation = |
| 7989 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7992 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7993 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7994 | MockWrite( |
| 7995 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7996 | "Host: www.example.org\r\n" |
| 7997 | "Connection: keep-alive\r\n" |
| 7998 | // Send preemptive authorization for MyRealm1 |
| 7999 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8000 | }; |
| 8001 | |
| 8002 | // The server didn't like the preemptive authorization, and |
| 8003 | // challenges us for a different realm (MyRealm2). |
| 8004 | MockRead data_reads1[] = { |
| 8005 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8006 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8007 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8008 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8009 | }; |
| 8010 | |
| 8011 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8012 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8013 | MockWrite( |
| 8014 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8015 | "Host: www.example.org\r\n" |
| 8016 | "Connection: keep-alive\r\n" |
| 8017 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8018 | }; |
| 8019 | |
| 8020 | // Sever accepts the authorization. |
| 8021 | MockRead data_reads2[] = { |
| 8022 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8023 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8025 | }; |
| 8026 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8027 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8028 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8030 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8032 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8034 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8036 | |
| 8037 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8038 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8040 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8041 | ASSERT_TRUE(response); |
| 8042 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8043 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8044 | EXPECT_EQ("http://www.example.org", |
| 8045 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8046 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8047 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8049 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8051 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8052 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8054 | |
| 8055 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8056 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8058 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8059 | ASSERT_TRUE(response); |
| 8060 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8061 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8062 | } |
| 8063 | |
| 8064 | // ------------------------------------------------------------------------ |
| 8065 | |
| 8066 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8067 | // succeed with preemptive authorization. |
| 8068 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8069 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8071 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8072 | request.traffic_annotation = |
| 8073 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8076 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8077 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8078 | MockWrite( |
| 8079 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8080 | "Host: www.example.org\r\n" |
| 8081 | "Connection: keep-alive\r\n" |
| 8082 | // The authorization for MyRealm1 gets sent preemptively |
| 8083 | // (since the url is in the same protection space) |
| 8084 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8085 | }; |
| 8086 | |
| 8087 | // Sever accepts the preemptive authorization |
| 8088 | MockRead data_reads1[] = { |
| 8089 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8090 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8091 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8092 | }; |
| 8093 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8094 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8095 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8096 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8097 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8098 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8099 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8101 | |
| 8102 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8103 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8105 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8106 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8107 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8108 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8109 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8110 | } |
| 8111 | |
| 8112 | // ------------------------------------------------------------------------ |
| 8113 | |
| 8114 | // Transaction 4: request another URL in MyRealm (however the |
| 8115 | // url is not known to belong to the protection space, so no pre-auth). |
| 8116 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8117 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8119 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8120 | request.traffic_annotation = |
| 8121 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8124 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8125 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8126 | MockWrite( |
| 8127 | "GET /x/1 HTTP/1.1\r\n" |
| 8128 | "Host: www.example.org\r\n" |
| 8129 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8130 | }; |
| 8131 | |
| 8132 | MockRead data_reads1[] = { |
| 8133 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8134 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8135 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8136 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8137 | }; |
| 8138 | |
| 8139 | // Resend with authorization from MyRealm's cache. |
| 8140 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8141 | MockWrite( |
| 8142 | "GET /x/1 HTTP/1.1\r\n" |
| 8143 | "Host: www.example.org\r\n" |
| 8144 | "Connection: keep-alive\r\n" |
| 8145 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8146 | }; |
| 8147 | |
| 8148 | // Sever accepts the authorization. |
| 8149 | MockRead data_reads2[] = { |
| 8150 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8151 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8152 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8153 | }; |
| 8154 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8155 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8156 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8157 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8158 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8159 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8160 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8161 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8162 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8164 | |
| 8165 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8168 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8169 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8170 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8172 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8173 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8174 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8176 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8177 | ASSERT_TRUE(response); |
| 8178 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8179 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8180 | } |
| 8181 | |
| 8182 | // ------------------------------------------------------------------------ |
| 8183 | |
| 8184 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8185 | // cached identity. Should invalidate and re-prompt. |
| 8186 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8187 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8188 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8189 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8190 | request.traffic_annotation = |
| 8191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8193 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8194 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8195 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8196 | MockWrite( |
| 8197 | "GET /p/q/t HTTP/1.1\r\n" |
| 8198 | "Host: www.example.org\r\n" |
| 8199 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8200 | }; |
| 8201 | |
| 8202 | MockRead data_reads1[] = { |
| 8203 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8204 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8205 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8206 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8207 | }; |
| 8208 | |
| 8209 | // Resend with authorization from cache for MyRealm. |
| 8210 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8211 | MockWrite( |
| 8212 | "GET /p/q/t HTTP/1.1\r\n" |
| 8213 | "Host: www.example.org\r\n" |
| 8214 | "Connection: keep-alive\r\n" |
| 8215 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8216 | }; |
| 8217 | |
| 8218 | // Sever rejects the authorization. |
| 8219 | MockRead data_reads2[] = { |
| 8220 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8221 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8222 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8223 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8224 | }; |
| 8225 | |
| 8226 | // At this point we should prompt for new credentials for MyRealm. |
| 8227 | // Restart with username=foo3, password=foo4. |
| 8228 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8229 | MockWrite( |
| 8230 | "GET /p/q/t HTTP/1.1\r\n" |
| 8231 | "Host: www.example.org\r\n" |
| 8232 | "Connection: keep-alive\r\n" |
| 8233 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8234 | }; |
| 8235 | |
| 8236 | // Sever accepts the authorization. |
| 8237 | MockRead data_reads3[] = { |
| 8238 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8239 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8240 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8241 | }; |
| 8242 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8243 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8244 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8245 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8246 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8247 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8248 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8250 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8251 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8252 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8254 | |
| 8255 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8258 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8259 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8260 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8261 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8262 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8263 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8264 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8265 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8266 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8267 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8268 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8269 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8270 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8272 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8273 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8275 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8276 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8277 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8279 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8280 | ASSERT_TRUE(response); |
| 8281 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8282 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8283 | } |
| 8284 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8285 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8286 | // Tests that nonce count increments when multiple auth attempts |
| 8287 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8288 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8289 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8290 | new HttpAuthHandlerDigest::Factory(); |
| 8291 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8292 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8293 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8294 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8296 | |
| 8297 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8298 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8299 | HttpRequestInfo request; |
| 8300 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8301 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8302 | request.traffic_annotation = |
| 8303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8304 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8306 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8307 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8308 | MockWrite( |
| 8309 | "GET /x/y/z HTTP/1.1\r\n" |
| 8310 | "Host: www.example.org\r\n" |
| 8311 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8312 | }; |
| 8313 | |
| 8314 | MockRead data_reads1[] = { |
| 8315 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8316 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8317 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8318 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8319 | }; |
| 8320 | |
| 8321 | // Resend with authorization (username=foo, password=bar) |
| 8322 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8323 | MockWrite( |
| 8324 | "GET /x/y/z HTTP/1.1\r\n" |
| 8325 | "Host: www.example.org\r\n" |
| 8326 | "Connection: keep-alive\r\n" |
| 8327 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8328 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8329 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8330 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8331 | }; |
| 8332 | |
| 8333 | // Sever accepts the authorization. |
| 8334 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8335 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8336 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8337 | }; |
| 8338 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8339 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8340 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8342 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8343 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8344 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8345 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8346 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8347 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8348 | |
| 8349 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8350 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8352 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8353 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8354 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8356 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8358 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8359 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8361 | |
| 8362 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8365 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8366 | ASSERT_TRUE(response); |
| 8367 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8368 | } |
| 8369 | |
| 8370 | // ------------------------------------------------------------------------ |
| 8371 | |
| 8372 | // Transaction 2: Request another resource in digestive's protection space. |
| 8373 | // This will preemptively add an Authorization header which should have an |
| 8374 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8375 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8376 | HttpRequestInfo request; |
| 8377 | request.method = "GET"; |
| 8378 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8379 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8380 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8381 | request.traffic_annotation = |
| 8382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8384 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8385 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8386 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8387 | MockWrite( |
| 8388 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8389 | "Host: www.example.org\r\n" |
| 8390 | "Connection: keep-alive\r\n" |
| 8391 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8392 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8393 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8394 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8395 | }; |
| 8396 | |
| 8397 | // Sever accepts the authorization. |
| 8398 | MockRead data_reads1[] = { |
| 8399 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8400 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8402 | }; |
| 8403 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8404 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8405 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8407 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8409 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8411 | |
| 8412 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8416 | ASSERT_TRUE(response); |
| 8417 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8418 | } |
| 8419 | } |
| 8420 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8421 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8422 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8423 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8425 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8426 | |
| 8427 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8428 | trans.read_buf_ = new IOBuffer(15); |
| 8429 | trans.read_buf_len_ = 15; |
| 8430 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8431 | |
| 8432 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8433 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8434 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8435 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8436 | response->response_time = base::Time::Now(); |
| 8437 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8438 | |
| 8439 | { // Setup state for response_.vary_data |
| 8440 | HttpRequestInfo request; |
| 8441 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8442 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8443 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8444 | request.extra_headers.SetHeader("Foo", "1"); |
| 8445 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8446 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8447 | } |
| 8448 | |
| 8449 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8450 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8451 | |
| 8452 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8453 | EXPECT_FALSE(trans.read_buf_); |
| 8454 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8455 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8456 | EXPECT_FALSE(response->auth_challenge); |
| 8457 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8458 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8459 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8460 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8461 | } |
| 8462 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8463 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8464 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8465 | HttpRequestInfo request; |
| 8466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8467 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8468 | request.traffic_annotation = |
| 8469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8473 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8474 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8475 | MockWrite( |
| 8476 | "GET / HTTP/1.1\r\n" |
| 8477 | "Host: www.example.org\r\n" |
| 8478 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8479 | }; |
| 8480 | |
| 8481 | MockRead data_reads[] = { |
| 8482 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8483 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8484 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8485 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8486 | }; |
| 8487 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8488 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8489 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8490 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8491 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8492 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8493 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8495 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8498 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8499 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8500 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8501 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8502 | |
| 8503 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8504 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8506 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8508 | |
| 8509 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8512 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8513 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8514 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8515 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8516 | } |
| 8517 | |
| 8518 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8519 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8520 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8521 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8522 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8523 | |
| 8524 | HttpRequestInfo request; |
| 8525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8527 | request.traffic_annotation = |
| 8528 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8529 | |
| 8530 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8531 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8532 | "Host: www.example.org:443\r\n" |
| 8533 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8534 | }; |
| 8535 | |
| 8536 | MockRead proxy_reads[] = { |
| 8537 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8538 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8539 | }; |
| 8540 | |
| 8541 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8542 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8543 | "Host: www.example.org:443\r\n" |
| 8544 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8545 | MockWrite("GET / HTTP/1.1\r\n" |
| 8546 | "Host: www.example.org\r\n" |
| 8547 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8548 | }; |
| 8549 | |
| 8550 | MockRead data_reads[] = { |
| 8551 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8552 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8553 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8554 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8555 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8556 | }; |
| 8557 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8558 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 8559 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8560 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8561 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8562 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8563 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8568 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8569 | |
| 8570 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8571 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8572 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8574 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8578 | |
| 8579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8580 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8582 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8584 | |
| 8585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8586 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8589 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8590 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8591 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8592 | } |
| 8593 | } |
| 8594 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8595 | |
| 8596 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8597 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8598 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8599 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8600 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8601 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8602 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8603 | |
| 8604 | HttpRequestInfo request; |
| 8605 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8606 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8607 | request.traffic_annotation = |
| 8608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8609 | |
| 8610 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8611 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8612 | "Host: www.example.org:443\r\n" |
| 8613 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8614 | MockWrite("GET / HTTP/1.1\r\n" |
| 8615 | "Host: www.example.org\r\n" |
| 8616 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8617 | }; |
| 8618 | |
| 8619 | MockRead data_reads[] = { |
| 8620 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8621 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8622 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8623 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8624 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8625 | }; |
| 8626 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8627 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8628 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8629 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8630 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8631 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8635 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8640 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8642 | |
| 8643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8644 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8645 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8646 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8647 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8648 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8649 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8650 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8651 | EXPECT_EQ(200, response->headers->response_code()); |
| 8652 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8653 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8654 | |
| 8655 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8656 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8657 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8658 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8659 | } |
| 8660 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8661 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8662 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8663 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8664 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8665 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8666 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8667 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8668 | |
| 8669 | HttpRequestInfo request; |
| 8670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8671 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8672 | request.traffic_annotation = |
| 8673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8674 | |
| 8675 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8676 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8677 | "Host: www.example.org:443\r\n" |
| 8678 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8679 | }; |
| 8680 | |
| 8681 | MockRead data_reads[] = { |
| 8682 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8683 | MockRead("Location: http://login.example.com/\r\n"), |
| 8684 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8686 | }; |
| 8687 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8688 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8689 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8690 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8694 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8701 | |
| 8702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8703 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8704 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8705 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8706 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8707 | |
| 8708 | EXPECT_EQ(302, response->headers->response_code()); |
| 8709 | std::string url; |
| 8710 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8711 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8712 | |
| 8713 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8714 | // timing for the proxy connection instead of the connection to the host, |
| 8715 | // and no send / receive times. |
| 8716 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8717 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8718 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8719 | |
| 8720 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8721 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8722 | |
| 8723 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8724 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8725 | load_timing_info.proxy_resolve_end); |
| 8726 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8727 | load_timing_info.connect_timing.connect_start); |
| 8728 | ExpectConnectTimingHasTimes( |
| 8729 | load_timing_info.connect_timing, |
| 8730 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8731 | |
| 8732 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8733 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8734 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8735 | } |
| 8736 | |
| 8737 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8738 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8739 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8740 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8741 | |
| 8742 | HttpRequestInfo request; |
| 8743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8744 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8745 | request.traffic_annotation = |
| 8746 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8747 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8748 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8749 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8750 | spdy::SpdySerializedFrame goaway( |
| 8751 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8752 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8753 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8754 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8755 | }; |
| 8756 | |
| 8757 | static const char* const kExtraHeaders[] = { |
| 8758 | "location", |
| 8759 | "http://login.example.com/", |
| 8760 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8761 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8762 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8763 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8764 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8765 | }; |
| 8766 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8767 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8768 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8769 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8770 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8772 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8774 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8781 | |
| 8782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8783 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8784 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8785 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8786 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8787 | |
| 8788 | EXPECT_EQ(302, response->headers->response_code()); |
| 8789 | std::string url; |
| 8790 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8791 | EXPECT_EQ("http://login.example.com/", url); |
| 8792 | } |
| 8793 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8794 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8795 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8796 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8797 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8798 | |
| 8799 | HttpRequestInfo request; |
| 8800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8801 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8802 | request.traffic_annotation = |
| 8803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8804 | |
| 8805 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8806 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8807 | "Host: www.example.org:443\r\n" |
| 8808 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8809 | }; |
| 8810 | |
| 8811 | MockRead data_reads[] = { |
| 8812 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8813 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8814 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8815 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8816 | }; |
| 8817 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8818 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8819 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8820 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8822 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8824 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8825 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8828 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8829 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8831 | |
| 8832 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8833 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8834 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8835 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8836 | } |
| 8837 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8838 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8839 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8840 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8841 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8842 | |
| 8843 | HttpRequestInfo request; |
| 8844 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8845 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8846 | request.traffic_annotation = |
| 8847 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8848 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8849 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8850 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8851 | spdy::SpdySerializedFrame rst( |
| 8852 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8853 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8854 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8855 | }; |
| 8856 | |
| 8857 | static const char* const kExtraHeaders[] = { |
| 8858 | "location", |
| 8859 | "http://login.example.com/", |
| 8860 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8861 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8862 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8863 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8864 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8865 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8866 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8867 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8868 | }; |
| 8869 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8870 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8871 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8872 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8873 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8874 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8877 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8881 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8882 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8884 | |
| 8885 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8886 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8887 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8888 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8889 | } |
| 8890 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8891 | // Test the request-challenge-retry sequence for basic auth, through |
| 8892 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8893 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8894 | HttpRequestInfo request; |
| 8895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8896 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8897 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8898 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8899 | request.traffic_annotation = |
| 8900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8901 | |
| 8902 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8903 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8904 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8905 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8906 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8907 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8909 | |
| 8910 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8911 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8912 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8913 | spdy::SpdySerializedFrame rst( |
| 8914 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8915 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8917 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8918 | // be issuing -- the final header line contains the credentials. |
| 8919 | const char* const kAuthCredentials[] = { |
| 8920 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8921 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8922 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8923 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8924 | HostPortPair("www.example.org", 443))); |
| 8925 | // fetch https://www.example.org/ via HTTP |
| 8926 | const char get[] = |
| 8927 | "GET / HTTP/1.1\r\n" |
| 8928 | "Host: www.example.org\r\n" |
| 8929 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8930 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8931 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8932 | |
| 8933 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8934 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8935 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8936 | }; |
| 8937 | |
| 8938 | // The proxy responds to the connect with a 407, using a persistent |
| 8939 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8940 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8941 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8942 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8943 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8944 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8945 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8946 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8947 | spdy::SpdySerializedFrame conn_resp( |
| 8948 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8949 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8950 | "Content-Length: 5\r\n\r\n"; |
| 8951 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8952 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8953 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 8954 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8955 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8956 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8957 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8958 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8959 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8960 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8961 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8962 | }; |
| 8963 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8964 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8965 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8966 | // Negotiate SPDY to the proxy |
| 8967 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8968 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8970 | // Vanilla SSL to the server |
| 8971 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8973 | |
| 8974 | TestCompletionCallback callback1; |
| 8975 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8976 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8977 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8978 | |
| 8979 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8981 | |
| 8982 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8983 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8984 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8985 | log.GetEntries(&entries); |
| 8986 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8987 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8988 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8989 | ExpectLogContainsSomewhere( |
| 8990 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8991 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8992 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8993 | |
| 8994 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8995 | ASSERT_TRUE(response); |
| 8996 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8997 | EXPECT_EQ(407, response->headers->response_code()); |
| 8998 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8999 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9000 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9001 | |
| 9002 | TestCompletionCallback callback2; |
| 9003 | |
| 9004 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9005 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9007 | |
| 9008 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9010 | |
| 9011 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9012 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9013 | |
| 9014 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9015 | EXPECT_EQ(200, response->headers->response_code()); |
| 9016 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9017 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9018 | |
| 9019 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9020 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9021 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9022 | LoadTimingInfo load_timing_info; |
| 9023 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9024 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9025 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9026 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9027 | trans.reset(); |
| 9028 | session->CloseAllConnections(); |
| 9029 | } |
| 9030 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9031 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9032 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9033 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9034 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9035 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9036 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9037 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9038 | HttpRequestInfo request; |
| 9039 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9040 | request.traffic_annotation = |
| 9041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9042 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9043 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9044 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9045 | push_request.method = "GET"; |
| 9046 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9047 | push_request.traffic_annotation = |
| 9048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9049 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9050 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9051 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9052 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9053 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9054 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9055 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9056 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9057 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9058 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9059 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9060 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9061 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9062 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9063 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9064 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9065 | |
| 9066 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9067 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9068 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9069 | }; |
| 9070 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9071 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9072 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9073 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9074 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9075 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9076 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9077 | spdy::SpdySerializedFrame stream1_body( |
| 9078 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9079 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9080 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9081 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9082 | |
| 9083 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9084 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9085 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9086 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9087 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9088 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9089 | }; |
| 9090 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9091 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9092 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9093 | // Negotiate SPDY to the proxy |
| 9094 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9095 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9097 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9098 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9100 | TestCompletionCallback callback; |
| 9101 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9103 | |
| 9104 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9105 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9106 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9107 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9108 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9109 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9110 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9112 | |
| 9113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9115 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9116 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9117 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9118 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9119 | |
| 9120 | EXPECT_EQ(200, response->headers->response_code()); |
| 9121 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9122 | |
| 9123 | std::string response_data; |
| 9124 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9125 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9126 | EXPECT_EQ("hello!", response_data); |
| 9127 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9128 | LoadTimingInfo load_timing_info; |
| 9129 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9130 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9131 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9132 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9133 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9134 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9135 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9136 | |
| 9137 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9138 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9139 | EXPECT_EQ("pushed", response_data); |
| 9140 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9141 | LoadTimingInfo push_load_timing_info; |
| 9142 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9143 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9144 | // The transactions should share a socket ID, despite being for different |
| 9145 | // origins. |
| 9146 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9147 | push_load_timing_info.socket_log_id); |
| 9148 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9149 | trans.reset(); |
| 9150 | push_trans.reset(); |
| 9151 | session->CloseAllConnections(); |
| 9152 | } |
| 9153 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9154 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9155 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9156 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9157 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9158 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9159 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9160 | HttpRequestInfo request; |
| 9161 | |
| 9162 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9163 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9164 | request.traffic_annotation = |
| 9165 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9166 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9167 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9168 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9169 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9170 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9171 | |
| 9172 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9173 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9174 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9175 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9176 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9177 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9178 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9179 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9180 | spdy::SpdySerializedFrame push_rst( |
| 9181 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9182 | |
| 9183 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9184 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9185 | }; |
| 9186 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9187 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9188 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9189 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9190 | spdy::SpdySerializedFrame stream1_body( |
| 9191 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9192 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9193 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9194 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9195 | |
| 9196 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9197 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9198 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9199 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9200 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9201 | }; |
| 9202 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9203 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9204 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9205 | // Negotiate SPDY to the proxy |
| 9206 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9207 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9209 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9210 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9211 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9212 | TestCompletionCallback callback; |
| 9213 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9215 | |
| 9216 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9218 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9219 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9220 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9221 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9222 | |
| 9223 | EXPECT_EQ(200, response->headers->response_code()); |
| 9224 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9225 | |
| 9226 | std::string response_data; |
| 9227 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9229 | EXPECT_EQ("hello!", response_data); |
| 9230 | |
| 9231 | trans.reset(); |
| 9232 | session->CloseAllConnections(); |
| 9233 | } |
| 9234 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9235 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9236 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9237 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9238 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9239 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9240 | proxy_delegate->set_trusted_spdy_proxy( |
| 9241 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9242 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9243 | HttpRequestInfo request; |
| 9244 | |
| 9245 | request.method = "GET"; |
| 9246 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9247 | request.traffic_annotation = |
| 9248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9249 | |
| 9250 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9251 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9252 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9253 | BoundTestNetLog log; |
| 9254 | session_deps_.net_log = log.bound().net_log(); |
| 9255 | |
| 9256 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9257 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9260 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9261 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9262 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9263 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9264 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9265 | |
| 9266 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9267 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9268 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9269 | }; |
| 9270 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9271 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9272 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9273 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9274 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9275 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9276 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9277 | spdy::SpdySerializedFrame stream1_body( |
| 9278 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9279 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9280 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9281 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9282 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 9283 | spdy::SpdySerializedFrame stream2_body( |
| 9284 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9285 | |
| 9286 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9287 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9288 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9289 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9290 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9291 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9292 | }; |
| 9293 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9294 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9295 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9296 | // Negotiate SPDY to the proxy |
| 9297 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9298 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9300 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9301 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9302 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9303 | TestCompletionCallback callback; |
| 9304 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9306 | |
| 9307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9308 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9309 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9310 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9311 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9312 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9313 | |
| 9314 | EXPECT_EQ(200, response->headers->response_code()); |
| 9315 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9316 | |
| 9317 | std::string response_data; |
| 9318 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9319 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9320 | EXPECT_EQ("hello!", response_data); |
| 9321 | |
| 9322 | trans.reset(); |
| 9323 | session->CloseAllConnections(); |
| 9324 | } |
| 9325 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9326 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9327 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9328 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9329 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9330 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9331 | |
| 9332 | HttpRequestInfo request; |
| 9333 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9334 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9335 | request.traffic_annotation = |
| 9336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9337 | |
| 9338 | // Attempt to fetch the URL from a server with a bad cert |
| 9339 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9340 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9341 | "Host: www.example.org:443\r\n" |
| 9342 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9343 | }; |
| 9344 | |
| 9345 | MockRead bad_cert_reads[] = { |
| 9346 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9347 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9348 | }; |
| 9349 | |
| 9350 | // Attempt to fetch the URL with a good cert |
| 9351 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9352 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9353 | "Host: www.example.org:443\r\n" |
| 9354 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9355 | MockWrite("GET / HTTP/1.1\r\n" |
| 9356 | "Host: www.example.org\r\n" |
| 9357 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9358 | }; |
| 9359 | |
| 9360 | MockRead good_cert_reads[] = { |
| 9361 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9362 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9363 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9364 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9365 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9366 | }; |
| 9367 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9368 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 9369 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9370 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9371 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9372 | |
| 9373 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9375 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9376 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9377 | |
| 9378 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9380 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9381 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9383 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9386 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9388 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9390 | |
| 9391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9392 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9394 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9396 | |
| 9397 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9398 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9400 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9401 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9402 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9403 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9404 | } |
| 9405 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9406 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9407 | HttpRequestInfo request; |
| 9408 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9409 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9410 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9411 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9412 | request.traffic_annotation = |
| 9413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9416 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9417 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9418 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9419 | MockWrite( |
| 9420 | "GET / HTTP/1.1\r\n" |
| 9421 | "Host: www.example.org\r\n" |
| 9422 | "Connection: keep-alive\r\n" |
| 9423 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9424 | }; |
| 9425 | |
| 9426 | // Lastly, the server responds with the actual content. |
| 9427 | MockRead data_reads[] = { |
| 9428 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9429 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9430 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9432 | }; |
| 9433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9434 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9437 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9438 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9439 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9441 | |
| 9442 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9444 | } |
| 9445 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9446 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9447 | HttpRequestInfo request; |
| 9448 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9449 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9450 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9451 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9452 | request.traffic_annotation = |
| 9453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9454 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9455 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9456 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9459 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9460 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9461 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9462 | "Host: www.example.org:443\r\n" |
| 9463 | "Proxy-Connection: keep-alive\r\n" |
| 9464 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9465 | }; |
| 9466 | MockRead data_reads[] = { |
| 9467 | // Return an error, so the transaction stops here (this test isn't |
| 9468 | // interested in the rest). |
| 9469 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9470 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9471 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9472 | }; |
| 9473 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9474 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9475 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9477 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9478 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9479 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9481 | |
| 9482 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9484 | } |
| 9485 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9486 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9487 | HttpRequestInfo request; |
| 9488 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9489 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9490 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9491 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9492 | request.traffic_annotation = |
| 9493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9494 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9497 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9498 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9499 | MockWrite( |
| 9500 | "GET / HTTP/1.1\r\n" |
| 9501 | "Host: www.example.org\r\n" |
| 9502 | "Connection: keep-alive\r\n" |
| 9503 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9504 | }; |
| 9505 | |
| 9506 | // Lastly, the server responds with the actual content. |
| 9507 | MockRead data_reads[] = { |
| 9508 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9509 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9510 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9511 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9512 | }; |
| 9513 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9514 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9515 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9516 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9517 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9518 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9519 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9521 | |
| 9522 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9523 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9524 | } |
| 9525 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9526 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9527 | HttpRequestInfo request; |
| 9528 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9529 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9530 | request.traffic_annotation = |
| 9531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9532 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9535 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9536 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9537 | MockWrite( |
| 9538 | "POST / HTTP/1.1\r\n" |
| 9539 | "Host: www.example.org\r\n" |
| 9540 | "Connection: keep-alive\r\n" |
| 9541 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9542 | }; |
| 9543 | |
| 9544 | // Lastly, the server responds with the actual content. |
| 9545 | MockRead data_reads[] = { |
| 9546 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9547 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9548 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9549 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9550 | }; |
| 9551 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9552 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9553 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9555 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9556 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9557 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9559 | |
| 9560 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9561 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9562 | } |
| 9563 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9564 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9565 | HttpRequestInfo request; |
| 9566 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9567 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9568 | request.traffic_annotation = |
| 9569 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9570 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9572 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9573 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9574 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9575 | MockWrite( |
| 9576 | "PUT / HTTP/1.1\r\n" |
| 9577 | "Host: www.example.org\r\n" |
| 9578 | "Connection: keep-alive\r\n" |
| 9579 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9580 | }; |
| 9581 | |
| 9582 | // Lastly, the server responds with the actual content. |
| 9583 | MockRead data_reads[] = { |
| 9584 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9586 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9587 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9588 | }; |
| 9589 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9590 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9593 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9595 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9597 | |
| 9598 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9599 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9600 | } |
| 9601 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9602 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9603 | HttpRequestInfo request; |
| 9604 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9605 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9606 | request.traffic_annotation = |
| 9607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9608 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9611 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9612 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9613 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9614 | "Host: www.example.org\r\n" |
| 9615 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9616 | }; |
| 9617 | |
| 9618 | // Lastly, the server responds with the actual content. |
| 9619 | MockRead data_reads[] = { |
| 9620 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9621 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9622 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9624 | }; |
| 9625 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9626 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9629 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9630 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9631 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9633 | |
| 9634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9635 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9636 | } |
| 9637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9638 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9639 | HttpRequestInfo request; |
| 9640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9641 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9642 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9643 | request.traffic_annotation = |
| 9644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9648 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9649 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9650 | MockWrite( |
| 9651 | "GET / HTTP/1.1\r\n" |
| 9652 | "Host: www.example.org\r\n" |
| 9653 | "Connection: keep-alive\r\n" |
| 9654 | "Pragma: no-cache\r\n" |
| 9655 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9656 | }; |
| 9657 | |
| 9658 | // Lastly, the server responds with the actual content. |
| 9659 | MockRead data_reads[] = { |
| 9660 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9661 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9662 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9663 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9664 | }; |
| 9665 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9666 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9667 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9669 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9670 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9671 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9673 | |
| 9674 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9675 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9676 | } |
| 9677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9678 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9679 | HttpRequestInfo request; |
| 9680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9681 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9682 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9683 | request.traffic_annotation = |
| 9684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9685 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9687 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9688 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9689 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9690 | MockWrite( |
| 9691 | "GET / HTTP/1.1\r\n" |
| 9692 | "Host: www.example.org\r\n" |
| 9693 | "Connection: keep-alive\r\n" |
| 9694 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9695 | }; |
| 9696 | |
| 9697 | // Lastly, the server responds with the actual content. |
| 9698 | MockRead data_reads[] = { |
| 9699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9703 | }; |
| 9704 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9705 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9707 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9708 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9712 | |
| 9713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9715 | } |
| 9716 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9717 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9718 | HttpRequestInfo request; |
| 9719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9720 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9721 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9722 | request.traffic_annotation = |
| 9723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9724 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9726 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9727 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9728 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9729 | MockWrite( |
| 9730 | "GET / HTTP/1.1\r\n" |
| 9731 | "Host: www.example.org\r\n" |
| 9732 | "Connection: keep-alive\r\n" |
| 9733 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9734 | }; |
| 9735 | |
| 9736 | // Lastly, the server responds with the actual content. |
| 9737 | MockRead data_reads[] = { |
| 9738 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9739 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9740 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9741 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9742 | }; |
| 9743 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9744 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9745 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9747 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9748 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9749 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9751 | |
| 9752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9754 | } |
| 9755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9756 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9757 | HttpRequestInfo request; |
| 9758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9759 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9760 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9761 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9762 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9763 | request.traffic_annotation = |
| 9764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9768 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9769 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9770 | MockWrite( |
| 9771 | "GET / HTTP/1.1\r\n" |
| 9772 | "Host: www.example.org\r\n" |
| 9773 | "Connection: keep-alive\r\n" |
| 9774 | "referer: www.foo.com\r\n" |
| 9775 | "hEllo: Kitty\r\n" |
| 9776 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9777 | }; |
| 9778 | |
| 9779 | // Lastly, the server responds with the actual content. |
| 9780 | MockRead data_reads[] = { |
| 9781 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9782 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9783 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9785 | }; |
| 9786 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9787 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9790 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9794 | |
| 9795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9797 | } |
| 9798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9799 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9800 | HttpRequestInfo request; |
| 9801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9802 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9803 | request.traffic_annotation = |
| 9804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9805 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9806 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9807 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9808 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9809 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9810 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9814 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9815 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9816 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9817 | |
| 9818 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9819 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9820 | MockWrite( |
| 9821 | "GET / HTTP/1.1\r\n" |
| 9822 | "Host: www.example.org\r\n" |
| 9823 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9824 | |
| 9825 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9826 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9827 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9828 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9829 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9830 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9831 | }; |
| 9832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9833 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9835 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9836 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9837 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9838 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9840 | |
| 9841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9844 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9845 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9846 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9847 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9848 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9849 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9850 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9851 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9852 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9853 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9854 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9856 | EXPECT_EQ("Payload", response_text); |
| 9857 | } |
| 9858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9859 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9860 | HttpRequestInfo request; |
| 9861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9862 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9863 | request.traffic_annotation = |
| 9864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9865 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9866 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9867 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9868 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9869 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9870 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9871 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9873 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9874 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9875 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9876 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9877 | |
| 9878 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9879 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9880 | arraysize(write_buffer)), |
| 9881 | MockWrite( |
| 9882 | "GET / HTTP/1.1\r\n" |
| 9883 | "Host: www.example.org\r\n" |
| 9884 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9885 | |
| 9886 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9887 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9888 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9889 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9890 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9891 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9892 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9893 | }; |
| 9894 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9895 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9897 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9898 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9901 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9905 | |
| 9906 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9908 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9909 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9910 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9911 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9912 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9914 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9915 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9916 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9917 | |
| 9918 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9919 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9921 | EXPECT_EQ("Payload", response_text); |
| 9922 | } |
| 9923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9924 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9925 | HttpRequestInfo request; |
| 9926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9927 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9928 | request.traffic_annotation = |
| 9929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9930 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9931 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9932 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9933 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9934 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9938 | |
| 9939 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9940 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9941 | |
| 9942 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9943 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9944 | MockWrite( |
| 9945 | "GET / HTTP/1.1\r\n" |
| 9946 | "Host: www.example.org\r\n" |
| 9947 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9948 | |
| 9949 | MockRead data_reads[] = { |
| 9950 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9951 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9952 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9953 | MockRead("Payload"), |
| 9954 | MockRead(SYNCHRONOUS, OK) |
| 9955 | }; |
| 9956 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9957 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9958 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9959 | |
| 9960 | TestCompletionCallback callback; |
| 9961 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9962 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9964 | |
| 9965 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9968 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9969 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9970 | |
| 9971 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9972 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9973 | TestLoadTimingNotReused(load_timing_info, |
| 9974 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9975 | |
| 9976 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9977 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9978 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9979 | EXPECT_EQ("Payload", response_text); |
| 9980 | } |
| 9981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9982 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9983 | HttpRequestInfo request; |
| 9984 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9985 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9986 | request.traffic_annotation = |
| 9987 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9988 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9989 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9990 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9991 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9992 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9993 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9996 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9997 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9998 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9999 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10000 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10001 | 0x05, // Version |
| 10002 | 0x01, // Command (CONNECT) |
| 10003 | 0x00, // Reserved. |
| 10004 | 0x03, // Address type (DOMAINNAME). |
| 10005 | 0x0F, // Length of domain (15) |
| 10006 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10007 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10008 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10009 | const char kSOCKS5OkResponse[] = |
| 10010 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10011 | |
| 10012 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10013 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10014 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10015 | MockWrite( |
| 10016 | "GET / HTTP/1.1\r\n" |
| 10017 | "Host: www.example.org\r\n" |
| 10018 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10019 | |
| 10020 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10021 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10022 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10023 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10024 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10025 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10026 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10027 | }; |
| 10028 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10029 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10030 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10032 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10034 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10036 | |
| 10037 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10038 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10040 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10041 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10042 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10043 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10044 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10045 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10046 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10047 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10048 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10049 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10050 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10051 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10052 | EXPECT_EQ("Payload", response_text); |
| 10053 | } |
| 10054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10055 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10056 | HttpRequestInfo request; |
| 10057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10058 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10059 | request.traffic_annotation = |
| 10060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10061 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10062 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10063 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10064 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10065 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10066 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10067 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10068 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10070 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10071 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10072 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10073 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10074 | 0x05, // Version |
| 10075 | 0x01, // Command (CONNECT) |
| 10076 | 0x00, // Reserved. |
| 10077 | 0x03, // Address type (DOMAINNAME). |
| 10078 | 0x0F, // Length of domain (15) |
| 10079 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10080 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10081 | }; |
| 10082 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10083 | const char kSOCKS5OkResponse[] = |
| 10084 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10085 | |
| 10086 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10087 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10088 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10089 | arraysize(kSOCKS5OkRequest)), |
| 10090 | MockWrite( |
| 10091 | "GET / HTTP/1.1\r\n" |
| 10092 | "Host: www.example.org\r\n" |
| 10093 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10094 | |
| 10095 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10096 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10097 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10098 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10099 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10100 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10101 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10102 | }; |
| 10103 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10104 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10106 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10107 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10108 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10110 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10112 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10114 | |
| 10115 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10118 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10119 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10120 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10121 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10122 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10123 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10124 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10125 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10126 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10127 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10128 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10130 | EXPECT_EQ("Payload", response_text); |
| 10131 | } |
| 10132 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10133 | namespace { |
| 10134 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10135 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10136 | |
| 10137 | struct GroupNameTest { |
| 10138 | std::string proxy_server; |
| 10139 | std::string url; |
| 10140 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10141 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10142 | }; |
| 10143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10144 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10145 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10147 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10148 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10149 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10150 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10151 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10152 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10153 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10154 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10155 | |
| 10156 | return session; |
| 10157 | } |
| 10158 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10159 | int GroupNameTransactionHelper(const std::string& url, |
| 10160 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10161 | HttpRequestInfo request; |
| 10162 | request.method = "GET"; |
| 10163 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10164 | request.traffic_annotation = |
| 10165 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10167 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10169 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10170 | |
| 10171 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10172 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10173 | } |
| 10174 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10175 | } // namespace |
| 10176 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10177 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10178 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10179 | { |
| 10180 | "", // unused |
| 10181 | "http://www.example.org/direct", |
| 10182 | "www.example.org:80", |
| 10183 | false, |
| 10184 | }, |
| 10185 | { |
| 10186 | "", // unused |
| 10187 | "http://[2001:1418:13:1::25]/direct", |
| 10188 | "[2001:1418:13:1::25]:80", |
| 10189 | false, |
| 10190 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10191 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10192 | // SSL Tests |
| 10193 | { |
| 10194 | "", // unused |
| 10195 | "https://www.example.org/direct_ssl", |
| 10196 | "ssl/www.example.org:443", |
| 10197 | true, |
| 10198 | }, |
| 10199 | { |
| 10200 | "", // unused |
| 10201 | "https://[2001:1418:13:1::25]/direct", |
| 10202 | "ssl/[2001:1418:13:1::25]:443", |
| 10203 | true, |
| 10204 | }, |
| 10205 | { |
| 10206 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10207 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10208 | "ssl/host.with.alternate:443", |
| 10209 | true, |
| 10210 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10211 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10212 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10213 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10214 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10215 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10216 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10217 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10218 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10219 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10220 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10221 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10222 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10223 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10224 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10225 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10226 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10227 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10228 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10229 | |
| 10230 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10231 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10232 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10233 | EXPECT_EQ(tests[i].expected_group_name, |
| 10234 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10235 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10236 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10237 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10238 | } |
| 10239 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10240 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10241 | // When SSL proxy is not in use, socket must be requested from |
| 10242 | // |transport_conn_pool|. |
| 10243 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10244 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10245 | } |
| 10246 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10247 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10248 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10249 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10250 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10251 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10252 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10253 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10254 | // SSL Tests |
| 10255 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10256 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10257 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10258 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10259 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10260 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10261 | "http_proxy", "https://host.with.alternate/direct", |
| 10262 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10263 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10264 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10265 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10266 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10267 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10269 | }; |
| 10270 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10271 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10272 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10273 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10274 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10275 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10276 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10277 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10278 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10279 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10280 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10281 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10282 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10283 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10284 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10285 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10286 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10287 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10288 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10289 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10290 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10291 | |
| 10292 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10293 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10294 | if (tests[i].ssl) |
| 10295 | EXPECT_EQ(tests[i].expected_group_name, |
| 10296 | ssl_conn_pool->last_group_name_received()); |
| 10297 | else |
| 10298 | EXPECT_EQ(tests[i].expected_group_name, |
| 10299 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10300 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10301 | } |
| 10302 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10303 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10304 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10305 | { |
| 10306 | "socks4://socks_proxy:1080", |
| 10307 | "http://www.example.org/socks4_direct", |
| 10308 | "socks4/www.example.org:80", |
| 10309 | false, |
| 10310 | }, |
| 10311 | { |
| 10312 | "socks5://socks_proxy:1080", |
| 10313 | "http://www.example.org/socks5_direct", |
| 10314 | "socks5/www.example.org:80", |
| 10315 | false, |
| 10316 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10317 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10318 | // SSL Tests |
| 10319 | { |
| 10320 | "socks4://socks_proxy:1080", |
| 10321 | "https://www.example.org/socks4_ssl", |
| 10322 | "socks4/ssl/www.example.org:443", |
| 10323 | true, |
| 10324 | }, |
| 10325 | { |
| 10326 | "socks5://socks_proxy:1080", |
| 10327 | "https://www.example.org/socks5_ssl", |
| 10328 | "socks5/ssl/www.example.org:443", |
| 10329 | true, |
| 10330 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10332 | { |
| 10333 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10334 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10335 | "socks4/ssl/host.with.alternate:443", |
| 10336 | true, |
| 10337 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10338 | }; |
| 10339 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10340 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10341 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10342 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10343 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10344 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10345 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10346 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10347 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10348 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10349 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10350 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10351 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10352 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10353 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10354 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10355 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10356 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10357 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10358 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10359 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10362 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10363 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10364 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10365 | if (tests[i].ssl) |
| 10366 | EXPECT_EQ(tests[i].expected_group_name, |
| 10367 | ssl_conn_pool->last_group_name_received()); |
| 10368 | else |
| 10369 | EXPECT_EQ(tests[i].expected_group_name, |
| 10370 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10371 | } |
| 10372 | } |
| 10373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10374 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10375 | HttpRequestInfo request; |
| 10376 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10377 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10378 | request.traffic_annotation = |
| 10379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10380 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10381 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10382 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10383 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10384 | // This simulates failure resolving all hostnames; that means we will fail |
| 10385 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10386 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10391 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10393 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10395 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10397 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10398 | } |
| 10399 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10400 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10401 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10402 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10403 | HttpRequestInfo request_info; |
| 10404 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10405 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10406 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10407 | request_info.traffic_annotation = |
| 10408 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10409 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10410 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10411 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10412 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10415 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10416 | // 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] | 10417 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10418 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10419 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10420 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10421 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10422 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10423 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10425 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10427 | |
| 10428 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10429 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10430 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10431 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10432 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10433 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10434 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10435 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10436 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10437 | // 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] | 10438 | // we can tell if the next lookup hit the cache, or the "network". |
| 10439 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10440 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10441 | |
| 10442 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10443 | // 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] | 10444 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10445 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10447 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10448 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10449 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10450 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10451 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10452 | |
| 10453 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10454 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10455 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10456 | } |
| 10457 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10458 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10459 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10460 | HttpRequestInfo request; |
| 10461 | request.method = "GET"; |
| 10462 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10463 | request.traffic_annotation = |
| 10464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10465 | |
| 10466 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10467 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10468 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10469 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10473 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10476 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10477 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10479 | |
| 10480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10481 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10482 | |
| 10483 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10484 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10485 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10486 | } |
| 10487 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10488 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10489 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10490 | HttpRequestInfo request; |
| 10491 | request.method = "GET"; |
| 10492 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10493 | request.traffic_annotation = |
| 10494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10495 | |
| 10496 | MockRead data_reads[] = { |
| 10497 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10498 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10499 | }; |
| 10500 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10501 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10502 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10505 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10508 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10509 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10510 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10511 | |
| 10512 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10513 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10515 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10516 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10517 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10518 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10519 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10520 | |
| 10521 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10522 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10523 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10524 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10525 | |
| 10526 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10527 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10528 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10529 | } |
| 10530 | |
| 10531 | // Make sure that a dropped connection while draining the body for auth |
| 10532 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10533 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10534 | HttpRequestInfo request; |
| 10535 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10536 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10537 | request.traffic_annotation = |
| 10538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10539 | |
| 10540 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10541 | MockWrite( |
| 10542 | "GET / HTTP/1.1\r\n" |
| 10543 | "Host: www.example.org\r\n" |
| 10544 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10545 | }; |
| 10546 | |
| 10547 | MockRead data_reads1[] = { |
| 10548 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10549 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10551 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10552 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10553 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10554 | }; |
| 10555 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10556 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10557 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10559 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10560 | // be issuing -- the final header line contains the credentials. |
| 10561 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10562 | MockWrite( |
| 10563 | "GET / HTTP/1.1\r\n" |
| 10564 | "Host: www.example.org\r\n" |
| 10565 | "Connection: keep-alive\r\n" |
| 10566 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10567 | }; |
| 10568 | |
| 10569 | // Lastly, the server responds with the actual content. |
| 10570 | MockRead data_reads2[] = { |
| 10571 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10572 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10573 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10574 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10575 | }; |
| 10576 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10577 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10578 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10579 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10580 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10581 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10585 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10587 | |
| 10588 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10589 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10591 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10592 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10593 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10595 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10597 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10599 | |
| 10600 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10601 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10603 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10604 | ASSERT_TRUE(response); |
| 10605 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10606 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10607 | } |
| 10608 | |
| 10609 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10610 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10611 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10612 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10613 | |
| 10614 | HttpRequestInfo request; |
| 10615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10616 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10617 | request.traffic_annotation = |
| 10618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10619 | |
| 10620 | MockRead proxy_reads[] = { |
| 10621 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10622 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10623 | }; |
| 10624 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10625 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10626 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10627 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10631 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10632 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10633 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10634 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10635 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10637 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10638 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10640 | |
| 10641 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10642 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10643 | } |
| 10644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10645 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10646 | HttpRequestInfo request; |
| 10647 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10648 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10649 | request.traffic_annotation = |
| 10650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10651 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10652 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10653 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10654 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10655 | MockRead data_reads[] = { |
| 10656 | 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] | 10657 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10658 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10659 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10660 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10663 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [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] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10667 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10668 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10670 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10671 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10672 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10673 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10674 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10675 | |
| 10676 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10677 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10678 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10679 | } |
| 10680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10681 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10682 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10683 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10684 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10685 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10686 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10688 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10689 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10690 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10691 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10692 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10693 | |
| 10694 | HttpRequestInfo request; |
| 10695 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10696 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10697 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10698 | request.traffic_annotation = |
| 10699 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10703 | |
| 10704 | MockRead data_reads[] = { |
| 10705 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10706 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10707 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10708 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10709 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10710 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10712 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10713 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10714 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10716 | |
| 10717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10718 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10720 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10721 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10722 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10723 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10724 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10725 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10726 | } |
| 10727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10728 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10729 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10730 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10731 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10732 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10733 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10734 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10735 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10737 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10738 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10739 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10740 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10741 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10742 | |
| 10743 | HttpRequestInfo request; |
| 10744 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10745 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10746 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10747 | request.traffic_annotation = |
| 10748 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10749 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10750 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10753 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10754 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10757 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10759 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10761 | |
| 10762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10763 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10764 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10765 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10766 | } |
| 10767 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10768 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10769 | class FakeUploadElementReader : public UploadElementReader { |
| 10770 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10771 | FakeUploadElementReader() = default; |
| 10772 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10773 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10774 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10775 | |
| 10776 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10777 | int Init(CompletionOnceCallback callback) override { |
| 10778 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10779 | return ERR_IO_PENDING; |
| 10780 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10781 | uint64_t GetContentLength() const override { return 0; } |
| 10782 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10783 | int Read(IOBuffer* buf, |
| 10784 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10785 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10786 | return ERR_FAILED; |
| 10787 | } |
| 10788 | |
| 10789 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10790 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10791 | }; |
| 10792 | |
| 10793 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10794 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10795 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10796 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10797 | |
| 10798 | HttpRequestInfo request; |
| 10799 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10800 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10801 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10802 | request.traffic_annotation = |
| 10803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10804 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10806 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10807 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10808 | |
| 10809 | StaticSocketDataProvider data; |
| 10810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10811 | |
| 10812 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10813 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10815 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10816 | |
| 10817 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10818 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10819 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10820 | |
| 10821 | // Return Init()'s result after the transaction gets destroyed. |
| 10822 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10823 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10824 | } |
| 10825 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10826 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10827 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10828 | HttpRequestInfo request; |
| 10829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10830 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10831 | request.traffic_annotation = |
| 10832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10833 | |
| 10834 | // First transaction will request a resource and receive a Basic challenge |
| 10835 | // with realm="first_realm". |
| 10836 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10837 | MockWrite( |
| 10838 | "GET / HTTP/1.1\r\n" |
| 10839 | "Host: www.example.org\r\n" |
| 10840 | "Connection: keep-alive\r\n" |
| 10841 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10842 | }; |
| 10843 | MockRead data_reads1[] = { |
| 10844 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10845 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10846 | "\r\n"), |
| 10847 | }; |
| 10848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10849 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10850 | // for first_realm. The server will reject and provide a challenge with |
| 10851 | // second_realm. |
| 10852 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10853 | MockWrite( |
| 10854 | "GET / HTTP/1.1\r\n" |
| 10855 | "Host: www.example.org\r\n" |
| 10856 | "Connection: keep-alive\r\n" |
| 10857 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10858 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10859 | }; |
| 10860 | MockRead data_reads2[] = { |
| 10861 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10862 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10863 | "\r\n"), |
| 10864 | }; |
| 10865 | |
| 10866 | // This again fails, and goes back to first_realm. Make sure that the |
| 10867 | // entry is removed from cache. |
| 10868 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10869 | MockWrite( |
| 10870 | "GET / HTTP/1.1\r\n" |
| 10871 | "Host: www.example.org\r\n" |
| 10872 | "Connection: keep-alive\r\n" |
| 10873 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10874 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10875 | }; |
| 10876 | MockRead data_reads3[] = { |
| 10877 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10878 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10879 | "\r\n"), |
| 10880 | }; |
| 10881 | |
| 10882 | // Try one last time (with the correct password) and get the resource. |
| 10883 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10884 | MockWrite( |
| 10885 | "GET / HTTP/1.1\r\n" |
| 10886 | "Host: www.example.org\r\n" |
| 10887 | "Connection: keep-alive\r\n" |
| 10888 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10889 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10890 | }; |
| 10891 | MockRead data_reads4[] = { |
| 10892 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10893 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10894 | "Content-Length: 5\r\n" |
| 10895 | "\r\n" |
| 10896 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10897 | }; |
| 10898 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10899 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10900 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 10901 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 10902 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10904 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10905 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10906 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10907 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10908 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10912 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10913 | // Issue the first request with Authorize headers. There should be a |
| 10914 | // password prompt for first_realm waiting to be filled in after the |
| 10915 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10916 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10918 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10919 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10920 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10921 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10922 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10923 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10924 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10925 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10926 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10927 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10928 | |
| 10929 | // Issue the second request with an incorrect password. There should be a |
| 10930 | // password prompt for second_realm waiting to be filled in after the |
| 10931 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10932 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10933 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10934 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10935 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10936 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10937 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10938 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10939 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10940 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10941 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10942 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10943 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10944 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10945 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10946 | |
| 10947 | // Issue the third request with another incorrect password. There should be |
| 10948 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10949 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10950 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10951 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10952 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10953 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10955 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10956 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10957 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10958 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10959 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10960 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10961 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10962 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10963 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10964 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10965 | |
| 10966 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10967 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10968 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10969 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10971 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10972 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10973 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10974 | ASSERT_TRUE(response); |
| 10975 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10976 | } |
| 10977 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10978 | // Regression test for https://crbug.com/754395. |
| 10979 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10980 | MockRead data_reads[] = { |
| 10981 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10982 | MockRead(kAlternativeServiceHttpHeader), |
| 10983 | MockRead("\r\n"), |
| 10984 | MockRead("hello world"), |
| 10985 | MockRead(SYNCHRONOUS, OK), |
| 10986 | }; |
| 10987 | |
| 10988 | HttpRequestInfo request; |
| 10989 | request.method = "GET"; |
| 10990 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10991 | request.traffic_annotation = |
| 10992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10993 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10994 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10996 | |
| 10997 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10998 | ssl.ssl_info.cert = |
| 10999 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11000 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11001 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11002 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11003 | |
| 11004 | TestCompletionCallback callback; |
| 11005 | |
| 11006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11007 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11008 | |
| 11009 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11011 | |
| 11012 | url::SchemeHostPort test_server(request.url); |
| 11013 | HttpServerProperties* http_server_properties = |
| 11014 | session->http_server_properties(); |
| 11015 | EXPECT_TRUE( |
| 11016 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11017 | |
| 11018 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11019 | |
| 11020 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11021 | ASSERT_TRUE(response); |
| 11022 | ASSERT_TRUE(response->headers); |
| 11023 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11024 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11025 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11026 | |
| 11027 | std::string response_data; |
| 11028 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11029 | EXPECT_EQ("hello world", response_data); |
| 11030 | |
| 11031 | EXPECT_TRUE( |
| 11032 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11033 | } |
| 11034 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11035 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11036 | MockRead data_reads[] = { |
| 11037 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11038 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11039 | MockRead("\r\n"), |
| 11040 | MockRead("hello world"), |
| 11041 | MockRead(SYNCHRONOUS, OK), |
| 11042 | }; |
| 11043 | |
| 11044 | HttpRequestInfo request; |
| 11045 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11046 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11047 | request.traffic_annotation = |
| 11048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11049 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11050 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11052 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11053 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11054 | ssl.ssl_info.cert = |
| 11055 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11056 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11058 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11059 | TestCompletionCallback callback; |
| 11060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11064 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11066 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11067 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11068 | HttpServerProperties* http_server_properties = |
| 11069 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11070 | EXPECT_TRUE( |
| 11071 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11072 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11073 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11075 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11076 | ASSERT_TRUE(response); |
| 11077 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11078 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11079 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11080 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11081 | |
| 11082 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11083 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11084 | EXPECT_EQ("hello world", response_data); |
| 11085 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11086 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11087 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11088 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11089 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11090 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11091 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11092 | } |
| 11093 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11094 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11095 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11096 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11097 | MockRead data_reads[] = { |
| 11098 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11099 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11100 | MockRead("\r\n"), |
| 11101 | MockRead("hello world"), |
| 11102 | MockRead(SYNCHRONOUS, OK), |
| 11103 | }; |
| 11104 | |
| 11105 | HttpRequestInfo request; |
| 11106 | request.method = "GET"; |
| 11107 | request.url = GURL("http://www.example.org/"); |
| 11108 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11109 | request.traffic_annotation = |
| 11110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11111 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11112 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11113 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11114 | |
| 11115 | TestCompletionCallback callback; |
| 11116 | |
| 11117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11118 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11119 | |
| 11120 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11121 | HttpServerProperties* http_server_properties = |
| 11122 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11123 | EXPECT_TRUE( |
| 11124 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11125 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11126 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11128 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11130 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11131 | ASSERT_TRUE(response); |
| 11132 | ASSERT_TRUE(response->headers); |
| 11133 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11134 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11135 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11136 | |
| 11137 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11138 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11139 | EXPECT_EQ("hello world", response_data); |
| 11140 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11141 | EXPECT_TRUE( |
| 11142 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11143 | } |
| 11144 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11145 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11146 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11147 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11148 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11149 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11150 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11151 | HttpRequestInfo request; |
| 11152 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11153 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11154 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11155 | request.traffic_annotation = |
| 11156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11157 | |
| 11158 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11159 | StaticSocketDataProvider first_data; |
| 11160 | first_data.set_connect_data(mock_connect); |
| 11161 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11162 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11163 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11165 | |
| 11166 | MockRead data_reads[] = { |
| 11167 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11168 | MockRead(ASYNC, OK), |
| 11169 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11170 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11171 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11172 | |
| 11173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11174 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11175 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11176 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11177 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11178 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11179 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11180 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11181 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11183 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11184 | TestCompletionCallback callback; |
| 11185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11186 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11187 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11188 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11189 | } |
| 11190 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11191 | // Regression test for https://crbug.com/615497: |
| 11192 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11193 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11194 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11195 | HttpRequestInfo request; |
| 11196 | request.method = "GET"; |
| 11197 | request.url = GURL("http://www.example.org/"); |
| 11198 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11199 | request.traffic_annotation = |
| 11200 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11201 | |
| 11202 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11203 | StaticSocketDataProvider first_data; |
| 11204 | first_data.set_connect_data(mock_connect); |
| 11205 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11206 | |
| 11207 | MockRead data_reads[] = { |
| 11208 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11209 | MockRead(ASYNC, OK), |
| 11210 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11211 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11212 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11213 | |
| 11214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11215 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11216 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11217 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11218 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11219 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11220 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11221 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11224 | TestCompletionCallback callback; |
| 11225 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11226 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11227 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11228 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11229 | } |
| 11230 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11231 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11232 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11234 | HttpServerProperties* http_server_properties = |
| 11235 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11236 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11237 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11238 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11239 | http_server_properties->SetQuicAlternativeService( |
| 11240 | test_server, alternative_service, expiration, |
| 11241 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11242 | EXPECT_EQ( |
| 11243 | 1u, |
| 11244 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11245 | |
| 11246 | // Send a clear header. |
| 11247 | MockRead data_reads[] = { |
| 11248 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11249 | MockRead("Alt-Svc: clear\r\n"), |
| 11250 | MockRead("\r\n"), |
| 11251 | MockRead("hello world"), |
| 11252 | MockRead(SYNCHRONOUS, OK), |
| 11253 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11254 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11256 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11257 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11258 | ssl.ssl_info.cert = |
| 11259 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11260 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11262 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11263 | HttpRequestInfo request; |
| 11264 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11265 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11266 | request.traffic_annotation = |
| 11267 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11268 | |
| 11269 | TestCompletionCallback callback; |
| 11270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11271 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11272 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11273 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11274 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11276 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11277 | ASSERT_TRUE(response); |
| 11278 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11279 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11280 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11281 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11282 | |
| 11283 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11284 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11285 | EXPECT_EQ("hello world", response_data); |
| 11286 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11287 | EXPECT_TRUE( |
| 11288 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11289 | } |
| 11290 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11291 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11292 | MockRead data_reads[] = { |
| 11293 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11294 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11295 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11296 | MockRead("hello world"), |
| 11297 | MockRead(SYNCHRONOUS, OK), |
| 11298 | }; |
| 11299 | |
| 11300 | HttpRequestInfo request; |
| 11301 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11302 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11303 | request.traffic_annotation = |
| 11304 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11305 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11306 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11307 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11308 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11309 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11310 | ssl.ssl_info.cert = |
| 11311 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11312 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11314 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11315 | TestCompletionCallback callback; |
| 11316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11318 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11319 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11320 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11322 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11323 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11324 | HttpServerProperties* http_server_properties = |
| 11325 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11326 | EXPECT_TRUE( |
| 11327 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11328 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11329 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11332 | ASSERT_TRUE(response); |
| 11333 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11334 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11335 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11336 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11337 | |
| 11338 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11339 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11340 | EXPECT_EQ("hello world", response_data); |
| 11341 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11342 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11343 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11344 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11345 | |
| 11346 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11347 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11348 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11349 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11350 | 1234); |
| 11351 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11352 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11353 | } |
| 11354 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11355 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11356 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11357 | HostPortPair alternative("alternative.example.org", 443); |
| 11358 | std::string origin_url = "https://origin.example.org:443"; |
| 11359 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11360 | |
| 11361 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11362 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11363 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11365 | |
| 11366 | // HTTP/1.1 data for request. |
| 11367 | MockWrite http_writes[] = { |
| 11368 | MockWrite("GET / HTTP/1.1\r\n" |
| 11369 | "Host: alternative.example.org\r\n" |
| 11370 | "Connection: keep-alive\r\n\r\n"), |
| 11371 | }; |
| 11372 | |
| 11373 | MockRead http_reads[] = { |
| 11374 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11375 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11376 | "Content-Length: 40\r\n\r\n" |
| 11377 | "first HTTP/1.1 response from alternative"), |
| 11378 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11379 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11380 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11381 | |
| 11382 | StaticSocketDataProvider data_refused; |
| 11383 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11384 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11385 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11386 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11388 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11389 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11390 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11391 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11392 | http_server_properties->SetQuicAlternativeService( |
| 11393 | server, alternative_service, expiration, |
| 11394 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11395 | // Mark the QUIC alternative service as broken. |
| 11396 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11397 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11398 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11399 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11400 | request.method = "GET"; |
| 11401 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11402 | request.traffic_annotation = |
| 11403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11404 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11405 | TestCompletionCallback callback; |
| 11406 | NetErrorDetails details; |
| 11407 | EXPECT_FALSE(details.quic_broken); |
| 11408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11409 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11410 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11411 | EXPECT_TRUE(details.quic_broken); |
| 11412 | } |
| 11413 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11414 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11415 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11416 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11417 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11418 | std::string origin_url = "https://origin.example.org:443"; |
| 11419 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11420 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11421 | |
| 11422 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11423 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11424 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11426 | |
| 11427 | // HTTP/1.1 data for request. |
| 11428 | MockWrite http_writes[] = { |
| 11429 | MockWrite("GET / HTTP/1.1\r\n" |
| 11430 | "Host: alternative1.example.org\r\n" |
| 11431 | "Connection: keep-alive\r\n\r\n"), |
| 11432 | }; |
| 11433 | |
| 11434 | MockRead http_reads[] = { |
| 11435 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11436 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11437 | "Content-Length: 40\r\n\r\n" |
| 11438 | "first HTTP/1.1 response from alternative1"), |
| 11439 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11440 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11441 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11442 | |
| 11443 | StaticSocketDataProvider data_refused; |
| 11444 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11445 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11446 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11448 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11449 | session->http_server_properties(); |
| 11450 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11451 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11452 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11453 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11454 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11455 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11456 | alternative_service_info_vector.push_back( |
| 11457 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11458 | alternative_service1, expiration, |
| 11459 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11460 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11461 | alternative_service_info_vector.push_back( |
| 11462 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11463 | alternative_service2, expiration, |
| 11464 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11465 | |
| 11466 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11467 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11468 | |
| 11469 | // Mark one of the QUIC alternative service as broken. |
| 11470 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11471 | EXPECT_EQ(2u, |
| 11472 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11473 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11474 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11476 | request.method = "GET"; |
| 11477 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11478 | request.traffic_annotation = |
| 11479 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11480 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11481 | TestCompletionCallback callback; |
| 11482 | NetErrorDetails details; |
| 11483 | EXPECT_FALSE(details.quic_broken); |
| 11484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11485 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11486 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11487 | EXPECT_FALSE(details.quic_broken); |
| 11488 | } |
| 11489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11490 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11491 | HttpRequestInfo request; |
| 11492 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11493 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11494 | request.traffic_annotation = |
| 11495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11496 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11497 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11498 | StaticSocketDataProvider first_data; |
| 11499 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11500 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11501 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11502 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11504 | |
| 11505 | MockRead data_reads[] = { |
| 11506 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11507 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11508 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11509 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11510 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11511 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11514 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11515 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11516 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11517 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11518 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11519 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11520 | // Port is ignored by MockConnect anyway. |
| 11521 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11522 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11523 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11524 | http_server_properties->SetHttp2AlternativeService( |
| 11525 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11528 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11532 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11535 | ASSERT_TRUE(response); |
| 11536 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11538 | |
| 11539 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11540 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11541 | EXPECT_EQ("hello world", response_data); |
| 11542 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11543 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11544 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11545 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11546 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11547 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11548 | EXPECT_TRUE( |
| 11549 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11550 | } |
| 11551 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11552 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11553 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11554 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11555 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11556 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11557 | HttpRequestInfo restricted_port_request; |
| 11558 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11559 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11560 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11561 | restricted_port_request.traffic_annotation = |
| 11562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11563 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11564 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11565 | StaticSocketDataProvider first_data; |
| 11566 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11567 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11568 | |
| 11569 | MockRead data_reads[] = { |
| 11570 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11571 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11572 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11573 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11574 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11575 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11576 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11577 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11579 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11581 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11582 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11583 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11584 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11585 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11586 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11587 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11588 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11589 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11590 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11593 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11595 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11596 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11597 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11598 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11599 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11600 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11601 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11602 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11603 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11604 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11605 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11607 | |
| 11608 | HttpRequestInfo restricted_port_request; |
| 11609 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11610 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11611 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11612 | restricted_port_request.traffic_annotation = |
| 11613 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11614 | |
| 11615 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11616 | StaticSocketDataProvider first_data; |
| 11617 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11618 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11619 | |
| 11620 | MockRead data_reads[] = { |
| 11621 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11622 | MockRead("hello world"), |
| 11623 | MockRead(ASYNC, OK), |
| 11624 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11625 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11626 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11627 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11628 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11632 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11633 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11634 | session->http_server_properties(); |
| 11635 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11636 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11637 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11638 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11639 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11640 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11641 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11644 | TestCompletionCallback callback; |
| 11645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11646 | EXPECT_EQ(ERR_IO_PENDING, |
| 11647 | trans.Start(&restricted_port_request, callback.callback(), |
| 11648 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11649 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11650 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11651 | } |
| 11652 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11653 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11654 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11655 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11656 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11657 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11658 | HttpRequestInfo restricted_port_request; |
| 11659 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11660 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11661 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11662 | restricted_port_request.traffic_annotation = |
| 11663 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11664 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11665 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11666 | StaticSocketDataProvider first_data; |
| 11667 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11668 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11669 | |
| 11670 | MockRead data_reads[] = { |
| 11671 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11672 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11673 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11674 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11675 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11676 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11677 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11678 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11682 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11683 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11684 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11685 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11686 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11687 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11688 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11689 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11690 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11691 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11694 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11695 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11696 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11697 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11699 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11700 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11701 | } |
| 11702 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11703 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11704 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11705 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11706 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11707 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11708 | HttpRequestInfo unrestricted_port_request; |
| 11709 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11710 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11711 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11712 | unrestricted_port_request.traffic_annotation = |
| 11713 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11714 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11715 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11716 | StaticSocketDataProvider first_data; |
| 11717 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11718 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11719 | |
| 11720 | MockRead data_reads[] = { |
| 11721 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11722 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11723 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11724 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11725 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11726 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11727 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11728 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11729 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11732 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11733 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11734 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11735 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11736 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11737 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11738 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11739 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11740 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11741 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11743 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11744 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11746 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11747 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11749 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11750 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11751 | } |
| 11752 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11753 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11754 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11755 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11756 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11757 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11758 | HttpRequestInfo unrestricted_port_request; |
| 11759 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11760 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11761 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11762 | unrestricted_port_request.traffic_annotation = |
| 11763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11764 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11765 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11766 | StaticSocketDataProvider first_data; |
| 11767 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11768 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11769 | |
| 11770 | MockRead data_reads[] = { |
| 11771 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11772 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11773 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11774 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11775 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11776 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11777 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11778 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11780 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11782 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11783 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11784 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11785 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11786 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11787 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11788 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11789 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11790 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11791 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11793 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11794 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11796 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11797 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11799 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11800 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11801 | } |
| 11802 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11803 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 11804 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 11805 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11806 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11807 | HttpRequestInfo request; |
| 11808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11809 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11810 | request.traffic_annotation = |
| 11811 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11812 | |
| 11813 | // The alternate protocol request will error out before we attempt to connect, |
| 11814 | // so only the standard HTTP request will try to connect. |
| 11815 | MockRead data_reads[] = { |
| 11816 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11817 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11818 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11819 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11820 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11824 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11825 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11826 | session->http_server_properties(); |
| 11827 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11828 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11829 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11830 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11831 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11832 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11834 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11835 | TestCompletionCallback callback; |
| 11836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11837 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11839 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11840 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11841 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11842 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11843 | ASSERT_TRUE(response); |
| 11844 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11845 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11846 | |
| 11847 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11848 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11849 | EXPECT_EQ("hello world", response_data); |
| 11850 | } |
| 11851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11852 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11853 | HttpRequestInfo request; |
| 11854 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11855 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11856 | request.traffic_annotation = |
| 11857 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11858 | |
| 11859 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11860 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11861 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11862 | MockRead("\r\n"), |
| 11863 | MockRead("hello world"), |
| 11864 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11865 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11866 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11867 | StaticSocketDataProvider first_transaction(data_reads, |
| 11868 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11869 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11870 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11871 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11873 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11874 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11875 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 11876 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11877 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11878 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11879 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 11880 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 11881 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11882 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11883 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11884 | }; |
| 11885 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11886 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11887 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11888 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11889 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11890 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11891 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11892 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11893 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11894 | &hanging_non_alternate_protocol_socket); |
| 11895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11896 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11897 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11898 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11899 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11900 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11901 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11902 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11904 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11905 | |
| 11906 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11907 | ASSERT_TRUE(response); |
| 11908 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11909 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11910 | |
| 11911 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11912 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11913 | EXPECT_EQ("hello world", response_data); |
| 11914 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11915 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11916 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11918 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11920 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11921 | |
| 11922 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11923 | ASSERT_TRUE(response); |
| 11924 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11925 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11926 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11927 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11928 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11929 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11930 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11931 | } |
| 11932 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11933 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11934 | HttpRequestInfo request; |
| 11935 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11936 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11937 | request.traffic_annotation = |
| 11938 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11939 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11940 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11941 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11942 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11943 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11944 | MockRead("\r\n"), |
| 11945 | MockRead("hello world"), |
| 11946 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11947 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11948 | }; |
| 11949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11950 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11951 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11952 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11953 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11954 | ssl_http11.ssl_info.cert = |
| 11955 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11956 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11957 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11958 | |
| 11959 | // Second transaction starts an alternative and a non-alternative Job. |
| 11960 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11961 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11962 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11963 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11964 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11965 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11966 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11967 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11968 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11969 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11970 | // Third transaction starts an alternative and a non-alternative job. |
| 11971 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11972 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 11973 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11974 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 11975 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11976 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11977 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11978 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11979 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 11980 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 11981 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11982 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 11983 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11984 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11985 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11986 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11987 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11988 | }; |
| 11989 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11990 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11991 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11992 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11993 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11994 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11995 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11996 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11997 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12000 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12001 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12003 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12005 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12006 | |
| 12007 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12008 | ASSERT_TRUE(response); |
| 12009 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12010 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12011 | |
| 12012 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12013 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12014 | EXPECT_EQ("hello world", response_data); |
| 12015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12016 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12017 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12018 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12021 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12022 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12023 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12025 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12026 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12027 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12028 | |
| 12029 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12030 | ASSERT_TRUE(response); |
| 12031 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12032 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12033 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12034 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12035 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12036 | EXPECT_EQ("hello!", response_data); |
| 12037 | |
| 12038 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12039 | ASSERT_TRUE(response); |
| 12040 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12041 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12042 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12043 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12044 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12045 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12046 | } |
| 12047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12048 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12049 | HttpRequestInfo request; |
| 12050 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12051 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12052 | request.traffic_annotation = |
| 12053 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12054 | |
| 12055 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12056 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12057 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12058 | MockRead("\r\n"), |
| 12059 | MockRead("hello world"), |
| 12060 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12061 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12062 | }; |
| 12063 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12064 | StaticSocketDataProvider first_transaction(data_reads, |
| 12065 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12066 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12067 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12068 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12069 | ssl.ssl_info.cert = |
| 12070 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12071 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12073 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12074 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12075 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12076 | hanging_alternate_protocol_socket.set_connect_data( |
| 12077 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12078 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12079 | &hanging_alternate_protocol_socket); |
| 12080 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12081 | // 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] | 12082 | StaticSocketDataProvider second_transaction(data_reads, |
| 12083 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12084 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12087 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12088 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12090 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12091 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12092 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12093 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12095 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12096 | |
| 12097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12098 | ASSERT_TRUE(response); |
| 12099 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12100 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12101 | |
| 12102 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12103 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12104 | EXPECT_EQ("hello world", response_data); |
| 12105 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12106 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12107 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12109 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12111 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12112 | |
| 12113 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12114 | ASSERT_TRUE(response); |
| 12115 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12116 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12117 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12118 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12119 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12120 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12121 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12122 | } |
| 12123 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12124 | class CapturingProxyResolver : public ProxyResolver { |
| 12125 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12126 | CapturingProxyResolver() = default; |
| 12127 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12128 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12129 | int GetProxyForURL(const GURL& url, |
| 12130 | ProxyInfo* results, |
| 12131 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12132 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12133 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12134 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12135 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12136 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12137 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12138 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12139 | } |
| 12140 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12141 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12142 | |
| 12143 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12144 | std::vector<GURL> resolved_; |
| 12145 | |
| 12146 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12147 | }; |
| 12148 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12149 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12150 | public: |
| 12151 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12152 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12153 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12154 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12155 | std::unique_ptr<ProxyResolver>* resolver, |
| 12156 | const net::CompletionCallback& callback, |
| 12157 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12158 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12159 | return OK; |
| 12160 | } |
| 12161 | |
| 12162 | private: |
| 12163 | ProxyResolver* resolver_; |
| 12164 | }; |
| 12165 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12166 | // Test that proxy is resolved using the origin url, |
| 12167 | // regardless of the alternative server. |
| 12168 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12169 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12170 | ProxyConfig proxy_config; |
| 12171 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12172 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12173 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12174 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12175 | |
| 12176 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12177 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12178 | &capturing_proxy_resolver); |
| 12179 | |
| 12180 | TestNetLog net_log; |
| 12181 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12182 | session_deps_.proxy_resolution_service = |
| 12183 | std::make_unique<ProxyResolutionService>( |
| 12184 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12185 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12186 | |
| 12187 | session_deps_.net_log = &net_log; |
| 12188 | |
| 12189 | // Configure alternative service with a hostname that is not bypassed by the |
| 12190 | // proxy. |
| 12191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12192 | HttpServerProperties* http_server_properties = |
| 12193 | session->http_server_properties(); |
| 12194 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12195 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12196 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12197 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12198 | http_server_properties->SetHttp2AlternativeService( |
| 12199 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12200 | |
| 12201 | // Non-alternative job should hang. |
| 12202 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12203 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12204 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12205 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12206 | &hanging_alternate_protocol_socket); |
| 12207 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12208 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12209 | |
| 12210 | HttpRequestInfo request; |
| 12211 | request.method = "GET"; |
| 12212 | request.url = GURL("https://www.example.org/"); |
| 12213 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12214 | request.traffic_annotation = |
| 12215 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12216 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12217 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12218 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12219 | |
| 12220 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12221 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12222 | spdy::SpdySerializedFrame resp( |
| 12223 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12224 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12225 | MockRead spdy_reads[] = { |
| 12226 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12227 | }; |
| 12228 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12229 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12230 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12231 | |
| 12232 | TestCompletionCallback callback; |
| 12233 | |
| 12234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12235 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12236 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12237 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12238 | |
| 12239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12240 | ASSERT_TRUE(response); |
| 12241 | ASSERT_TRUE(response->headers); |
| 12242 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12243 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12244 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12245 | |
| 12246 | std::string response_data; |
| 12247 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12248 | EXPECT_EQ("hello!", response_data); |
| 12249 | |
| 12250 | // Origin host bypasses proxy, no resolution should have happened. |
| 12251 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12252 | } |
| 12253 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12254 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12255 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12256 | proxy_config.set_auto_detect(true); |
| 12257 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12258 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12259 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12260 | session_deps_.proxy_resolution_service = |
| 12261 | std::make_unique<ProxyResolutionService>( |
| 12262 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12263 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12264 | std::make_unique<CapturingProxyResolverFactory>( |
| 12265 | &capturing_proxy_resolver), |
| 12266 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12267 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12268 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12269 | |
| 12270 | HttpRequestInfo request; |
| 12271 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12272 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12273 | request.traffic_annotation = |
| 12274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12275 | |
| 12276 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12277 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12278 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12279 | MockRead("\r\n"), |
| 12280 | MockRead("hello world"), |
| 12281 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12282 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12283 | }; |
| 12284 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12285 | StaticSocketDataProvider first_transaction(data_reads, |
| 12286 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12287 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12288 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12289 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12291 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12292 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12293 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12294 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12295 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12296 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12297 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12298 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12299 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12300 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12301 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12302 | }; |
| 12303 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12304 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12305 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12306 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12307 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12308 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12309 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12310 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12311 | }; |
| 12312 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12313 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12314 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12315 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12316 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12317 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12318 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12319 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12320 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12321 | &hanging_non_alternate_protocol_socket); |
| 12322 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12323 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12326 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12327 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12328 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12329 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12330 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12331 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12332 | |
| 12333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12334 | ASSERT_TRUE(response); |
| 12335 | ASSERT_TRUE(response->headers); |
| 12336 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12337 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12338 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12339 | |
| 12340 | std::string response_data; |
| 12341 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12342 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12343 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12344 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12345 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12346 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12347 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12349 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12350 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12351 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12352 | ASSERT_TRUE(response); |
| 12353 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12354 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12355 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12356 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12357 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12358 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12359 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12360 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12361 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12362 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12363 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12364 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12365 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12366 | LoadTimingInfo load_timing_info; |
| 12367 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12368 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12369 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12370 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12371 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12372 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12373 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12374 | HttpRequestInfo request; |
| 12375 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12376 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12377 | request.traffic_annotation = |
| 12378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12379 | |
| 12380 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12381 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12382 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12383 | MockRead("\r\n"), |
| 12384 | MockRead("hello world"), |
| 12385 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12386 | }; |
| 12387 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12388 | StaticSocketDataProvider first_transaction(data_reads, |
| 12389 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12390 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12391 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12392 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12394 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12395 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12396 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12397 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12398 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12399 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12400 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 12401 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12402 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12403 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12404 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12405 | }; |
| 12406 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12407 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12408 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12409 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12410 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12413 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12414 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12415 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12416 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12417 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12419 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12420 | |
| 12421 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12422 | ASSERT_TRUE(response); |
| 12423 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12424 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12425 | |
| 12426 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12427 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12428 | EXPECT_EQ("hello world", response_data); |
| 12429 | |
| 12430 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12431 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12432 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12433 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12434 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12435 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12436 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12437 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12438 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12439 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12440 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12441 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12442 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12443 | |
| 12444 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12445 | ASSERT_TRUE(response); |
| 12446 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12447 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12448 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12449 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12450 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12451 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12452 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12453 | } |
| 12454 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12455 | // GenerateAuthToken is a mighty big test. |
| 12456 | // It tests all permutation of GenerateAuthToken behavior: |
| 12457 | // - Synchronous and Asynchronous completion. |
| 12458 | // - OK or error on completion. |
| 12459 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12460 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12461 | // - Non-authenticating and authenticating backend. |
| 12462 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12463 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12464 | // problems generating an auth token for an authenticating proxy, we don't |
| 12465 | // need to test all permutations of the backend server). |
| 12466 | // |
| 12467 | // The test proceeds by going over each of the configuration cases, and |
| 12468 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12469 | // specifies both the configuration for the test as well as the expectations |
| 12470 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12471 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12472 | static const char kServer[] = "http://www.example.com"; |
| 12473 | static const char kSecureServer[] = "https://www.example.com"; |
| 12474 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12475 | |
| 12476 | enum AuthTiming { |
| 12477 | AUTH_NONE, |
| 12478 | AUTH_SYNC, |
| 12479 | AUTH_ASYNC, |
| 12480 | }; |
| 12481 | |
| 12482 | const MockWrite kGet( |
| 12483 | "GET / HTTP/1.1\r\n" |
| 12484 | "Host: www.example.com\r\n" |
| 12485 | "Connection: keep-alive\r\n\r\n"); |
| 12486 | const MockWrite kGetProxy( |
| 12487 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12488 | "Host: www.example.com\r\n" |
| 12489 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12490 | const MockWrite kGetAuth( |
| 12491 | "GET / HTTP/1.1\r\n" |
| 12492 | "Host: www.example.com\r\n" |
| 12493 | "Connection: keep-alive\r\n" |
| 12494 | "Authorization: auth_token\r\n\r\n"); |
| 12495 | const MockWrite kGetProxyAuth( |
| 12496 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12497 | "Host: www.example.com\r\n" |
| 12498 | "Proxy-Connection: keep-alive\r\n" |
| 12499 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12500 | const MockWrite kGetAuthThroughProxy( |
| 12501 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12502 | "Host: www.example.com\r\n" |
| 12503 | "Proxy-Connection: keep-alive\r\n" |
| 12504 | "Authorization: auth_token\r\n\r\n"); |
| 12505 | const MockWrite kGetAuthWithProxyAuth( |
| 12506 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12507 | "Host: www.example.com\r\n" |
| 12508 | "Proxy-Connection: keep-alive\r\n" |
| 12509 | "Proxy-Authorization: auth_token\r\n" |
| 12510 | "Authorization: auth_token\r\n\r\n"); |
| 12511 | const MockWrite kConnect( |
| 12512 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12513 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12514 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12515 | const MockWrite kConnectProxyAuth( |
| 12516 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12517 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12518 | "Proxy-Connection: keep-alive\r\n" |
| 12519 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12520 | |
| 12521 | const MockRead kSuccess( |
| 12522 | "HTTP/1.1 200 OK\r\n" |
| 12523 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12524 | "Content-Length: 3\r\n\r\n" |
| 12525 | "Yes"); |
| 12526 | const MockRead kFailure( |
| 12527 | "Should not be called."); |
| 12528 | const MockRead kServerChallenge( |
| 12529 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12530 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12531 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12532 | "Content-Length: 14\r\n\r\n" |
| 12533 | "Unauthorized\r\n"); |
| 12534 | const MockRead kProxyChallenge( |
| 12535 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12536 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12537 | "Proxy-Connection: close\r\n" |
| 12538 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12539 | "Content-Length: 14\r\n\r\n" |
| 12540 | "Unauthorized\r\n"); |
| 12541 | const MockRead kProxyConnected( |
| 12542 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12543 | |
| 12544 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12545 | // no constructors, but the C++ compiler on Windows warns about |
| 12546 | // unspecified data in compound literals. So, moved to using constructors, |
| 12547 | // and TestRound's created with the default constructor should not be used. |
| 12548 | struct TestRound { |
| 12549 | TestRound() |
| 12550 | : expected_rv(ERR_UNEXPECTED), |
| 12551 | extra_write(NULL), |
| 12552 | extra_read(NULL) { |
| 12553 | } |
| 12554 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12555 | int expected_rv_arg) |
| 12556 | : write(write_arg), |
| 12557 | read(read_arg), |
| 12558 | expected_rv(expected_rv_arg), |
| 12559 | extra_write(NULL), |
| 12560 | extra_read(NULL) { |
| 12561 | } |
| 12562 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12563 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12564 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12565 | : write(write_arg), |
| 12566 | read(read_arg), |
| 12567 | expected_rv(expected_rv_arg), |
| 12568 | extra_write(extra_write_arg), |
| 12569 | extra_read(extra_read_arg) { |
| 12570 | } |
| 12571 | MockWrite write; |
| 12572 | MockRead read; |
| 12573 | int expected_rv; |
| 12574 | const MockWrite* extra_write; |
| 12575 | const MockRead* extra_read; |
| 12576 | }; |
| 12577 | |
| 12578 | static const int kNoSSL = 500; |
| 12579 | |
| 12580 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12581 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12582 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12583 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12584 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12585 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12586 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12587 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12588 | int num_auth_rounds; |
| 12589 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12590 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12591 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12592 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12593 | {__LINE__, |
| 12594 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12595 | AUTH_NONE, |
| 12596 | OK, |
| 12597 | kServer, |
| 12598 | AUTH_NONE, |
| 12599 | OK, |
| 12600 | 1, |
| 12601 | kNoSSL, |
| 12602 | {TestRound(kGet, kSuccess, OK)}}, |
| 12603 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12604 | {__LINE__, |
| 12605 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12606 | AUTH_NONE, |
| 12607 | OK, |
| 12608 | kServer, |
| 12609 | AUTH_SYNC, |
| 12610 | OK, |
| 12611 | 2, |
| 12612 | kNoSSL, |
| 12613 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12614 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12615 | {__LINE__, |
| 12616 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12617 | AUTH_NONE, |
| 12618 | OK, |
| 12619 | kServer, |
| 12620 | AUTH_SYNC, |
| 12621 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12622 | 3, |
| 12623 | kNoSSL, |
| 12624 | {TestRound(kGet, kServerChallenge, OK), |
| 12625 | TestRound(kGet, kServerChallenge, OK), |
| 12626 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12627 | {__LINE__, |
| 12628 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12629 | AUTH_NONE, |
| 12630 | OK, |
| 12631 | kServer, |
| 12632 | AUTH_SYNC, |
| 12633 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12634 | 2, |
| 12635 | kNoSSL, |
| 12636 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12637 | {__LINE__, |
| 12638 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12639 | AUTH_NONE, |
| 12640 | OK, |
| 12641 | kServer, |
| 12642 | AUTH_SYNC, |
| 12643 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12644 | 2, |
| 12645 | kNoSSL, |
| 12646 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12647 | {__LINE__, |
| 12648 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12649 | AUTH_SYNC, |
| 12650 | ERR_FAILED, |
| 12651 | kServer, |
| 12652 | AUTH_NONE, |
| 12653 | OK, |
| 12654 | 2, |
| 12655 | kNoSSL, |
| 12656 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12657 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12658 | {__LINE__, |
| 12659 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12660 | AUTH_ASYNC, |
| 12661 | ERR_FAILED, |
| 12662 | kServer, |
| 12663 | AUTH_NONE, |
| 12664 | OK, |
| 12665 | 2, |
| 12666 | kNoSSL, |
| 12667 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12668 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12669 | {__LINE__, |
| 12670 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12671 | AUTH_NONE, |
| 12672 | OK, |
| 12673 | kServer, |
| 12674 | AUTH_SYNC, |
| 12675 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12676 | 2, |
| 12677 | kNoSSL, |
| 12678 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12679 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12680 | {__LINE__, |
| 12681 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12682 | AUTH_NONE, |
| 12683 | OK, |
| 12684 | kServer, |
| 12685 | AUTH_ASYNC, |
| 12686 | ERR_FAILED, |
| 12687 | 2, |
| 12688 | kNoSSL, |
| 12689 | {TestRound(kGet, kServerChallenge, OK), |
| 12690 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12691 | {__LINE__, |
| 12692 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12693 | AUTH_NONE, |
| 12694 | OK, |
| 12695 | kServer, |
| 12696 | AUTH_ASYNC, |
| 12697 | OK, |
| 12698 | 2, |
| 12699 | kNoSSL, |
| 12700 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12701 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12702 | {__LINE__, |
| 12703 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12704 | AUTH_NONE, |
| 12705 | OK, |
| 12706 | kServer, |
| 12707 | AUTH_ASYNC, |
| 12708 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12709 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12710 | kNoSSL, |
| 12711 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12712 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12713 | TestRound(kGet, kServerChallenge, OK), |
| 12714 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12715 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12716 | {__LINE__, |
| 12717 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12718 | AUTH_NONE, |
| 12719 | OK, |
| 12720 | kServer, |
| 12721 | AUTH_NONE, |
| 12722 | OK, |
| 12723 | 1, |
| 12724 | kNoSSL, |
| 12725 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12726 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12727 | {__LINE__, |
| 12728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12729 | AUTH_NONE, |
| 12730 | OK, |
| 12731 | kServer, |
| 12732 | AUTH_SYNC, |
| 12733 | OK, |
| 12734 | 2, |
| 12735 | kNoSSL, |
| 12736 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12737 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12738 | {__LINE__, |
| 12739 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12740 | AUTH_NONE, |
| 12741 | OK, |
| 12742 | kServer, |
| 12743 | AUTH_SYNC, |
| 12744 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12745 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12746 | kNoSSL, |
| 12747 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12748 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12749 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12750 | {__LINE__, |
| 12751 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12752 | AUTH_NONE, |
| 12753 | OK, |
| 12754 | kServer, |
| 12755 | AUTH_ASYNC, |
| 12756 | OK, |
| 12757 | 2, |
| 12758 | kNoSSL, |
| 12759 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12760 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12761 | {__LINE__, |
| 12762 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12763 | AUTH_NONE, |
| 12764 | OK, |
| 12765 | kServer, |
| 12766 | AUTH_ASYNC, |
| 12767 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12768 | 2, |
| 12769 | kNoSSL, |
| 12770 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12771 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12772 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12773 | {__LINE__, |
| 12774 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12775 | AUTH_SYNC, |
| 12776 | OK, |
| 12777 | kServer, |
| 12778 | AUTH_NONE, |
| 12779 | OK, |
| 12780 | 2, |
| 12781 | kNoSSL, |
| 12782 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12783 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12784 | {__LINE__, |
| 12785 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12786 | AUTH_SYNC, |
| 12787 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12788 | kServer, |
| 12789 | AUTH_NONE, |
| 12790 | OK, |
| 12791 | 2, |
| 12792 | kNoSSL, |
| 12793 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12794 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12795 | {__LINE__, |
| 12796 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12797 | AUTH_ASYNC, |
| 12798 | OK, |
| 12799 | kServer, |
| 12800 | AUTH_NONE, |
| 12801 | OK, |
| 12802 | 2, |
| 12803 | kNoSSL, |
| 12804 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12805 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12806 | {__LINE__, |
| 12807 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12808 | AUTH_ASYNC, |
| 12809 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12810 | kServer, |
| 12811 | AUTH_NONE, |
| 12812 | OK, |
| 12813 | 2, |
| 12814 | kNoSSL, |
| 12815 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12816 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12817 | {__LINE__, |
| 12818 | kProxy, |
| 12819 | AUTH_ASYNC, |
| 12820 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12821 | kServer, |
| 12822 | AUTH_NONE, |
| 12823 | OK, |
| 12824 | 3, |
| 12825 | kNoSSL, |
| 12826 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12827 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12828 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12829 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12830 | {__LINE__, |
| 12831 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12832 | AUTH_SYNC, |
| 12833 | OK, |
| 12834 | kServer, |
| 12835 | AUTH_SYNC, |
| 12836 | OK, |
| 12837 | 3, |
| 12838 | kNoSSL, |
| 12839 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12840 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12841 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12842 | {__LINE__, |
| 12843 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12844 | AUTH_SYNC, |
| 12845 | OK, |
| 12846 | kServer, |
| 12847 | AUTH_SYNC, |
| 12848 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12849 | 3, |
| 12850 | kNoSSL, |
| 12851 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12852 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12853 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12854 | {__LINE__, |
| 12855 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12856 | AUTH_ASYNC, |
| 12857 | OK, |
| 12858 | kServer, |
| 12859 | AUTH_SYNC, |
| 12860 | OK, |
| 12861 | 3, |
| 12862 | kNoSSL, |
| 12863 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12864 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12865 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12866 | {__LINE__, |
| 12867 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12868 | AUTH_ASYNC, |
| 12869 | OK, |
| 12870 | kServer, |
| 12871 | AUTH_SYNC, |
| 12872 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12873 | 3, |
| 12874 | kNoSSL, |
| 12875 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12876 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12877 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12878 | {__LINE__, |
| 12879 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12880 | AUTH_SYNC, |
| 12881 | OK, |
| 12882 | kServer, |
| 12883 | AUTH_ASYNC, |
| 12884 | OK, |
| 12885 | 3, |
| 12886 | kNoSSL, |
| 12887 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12888 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12889 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12890 | {__LINE__, |
| 12891 | kProxy, |
| 12892 | AUTH_SYNC, |
| 12893 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12894 | kServer, |
| 12895 | AUTH_ASYNC, |
| 12896 | OK, |
| 12897 | 4, |
| 12898 | kNoSSL, |
| 12899 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12900 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12901 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12902 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12903 | {__LINE__, |
| 12904 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12905 | AUTH_SYNC, |
| 12906 | OK, |
| 12907 | kServer, |
| 12908 | AUTH_ASYNC, |
| 12909 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12910 | 3, |
| 12911 | kNoSSL, |
| 12912 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12913 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12914 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12915 | {__LINE__, |
| 12916 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12917 | AUTH_ASYNC, |
| 12918 | OK, |
| 12919 | kServer, |
| 12920 | AUTH_ASYNC, |
| 12921 | OK, |
| 12922 | 3, |
| 12923 | kNoSSL, |
| 12924 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12925 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12926 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12927 | {__LINE__, |
| 12928 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12929 | AUTH_ASYNC, |
| 12930 | OK, |
| 12931 | kServer, |
| 12932 | AUTH_ASYNC, |
| 12933 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12934 | 3, |
| 12935 | kNoSSL, |
| 12936 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12937 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12938 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12939 | {__LINE__, |
| 12940 | kProxy, |
| 12941 | AUTH_ASYNC, |
| 12942 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12943 | kServer, |
| 12944 | AUTH_ASYNC, |
| 12945 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12946 | 4, |
| 12947 | kNoSSL, |
| 12948 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12949 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12950 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12951 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12952 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12953 | {__LINE__, |
| 12954 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12955 | AUTH_NONE, |
| 12956 | OK, |
| 12957 | kSecureServer, |
| 12958 | AUTH_NONE, |
| 12959 | OK, |
| 12960 | 1, |
| 12961 | 0, |
| 12962 | {TestRound(kGet, kSuccess, OK)}}, |
| 12963 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12964 | {__LINE__, |
| 12965 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12966 | AUTH_NONE, |
| 12967 | OK, |
| 12968 | kSecureServer, |
| 12969 | AUTH_SYNC, |
| 12970 | OK, |
| 12971 | 2, |
| 12972 | 0, |
| 12973 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12974 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12975 | {__LINE__, |
| 12976 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12977 | AUTH_NONE, |
| 12978 | OK, |
| 12979 | kSecureServer, |
| 12980 | AUTH_SYNC, |
| 12981 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12982 | 2, |
| 12983 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12984 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12985 | {__LINE__, |
| 12986 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12987 | AUTH_NONE, |
| 12988 | OK, |
| 12989 | kSecureServer, |
| 12990 | AUTH_ASYNC, |
| 12991 | OK, |
| 12992 | 2, |
| 12993 | 0, |
| 12994 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12995 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12996 | {__LINE__, |
| 12997 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12998 | AUTH_NONE, |
| 12999 | OK, |
| 13000 | kSecureServer, |
| 13001 | AUTH_ASYNC, |
| 13002 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13003 | 2, |
| 13004 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13005 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13006 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13007 | {__LINE__, |
| 13008 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13009 | AUTH_NONE, |
| 13010 | OK, |
| 13011 | kSecureServer, |
| 13012 | AUTH_NONE, |
| 13013 | OK, |
| 13014 | 1, |
| 13015 | 0, |
| 13016 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13017 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13018 | {__LINE__, |
| 13019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13020 | AUTH_NONE, |
| 13021 | OK, |
| 13022 | kSecureServer, |
| 13023 | AUTH_SYNC, |
| 13024 | OK, |
| 13025 | 2, |
| 13026 | 0, |
| 13027 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13028 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13029 | {__LINE__, |
| 13030 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13031 | AUTH_NONE, |
| 13032 | OK, |
| 13033 | kSecureServer, |
| 13034 | AUTH_SYNC, |
| 13035 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13036 | 2, |
| 13037 | 0, |
| 13038 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13039 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13040 | {__LINE__, |
| 13041 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13042 | AUTH_NONE, |
| 13043 | OK, |
| 13044 | kSecureServer, |
| 13045 | AUTH_ASYNC, |
| 13046 | OK, |
| 13047 | 2, |
| 13048 | 0, |
| 13049 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13050 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13051 | {__LINE__, |
| 13052 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13053 | AUTH_NONE, |
| 13054 | OK, |
| 13055 | kSecureServer, |
| 13056 | AUTH_ASYNC, |
| 13057 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13058 | 2, |
| 13059 | 0, |
| 13060 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13061 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13062 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13063 | {__LINE__, |
| 13064 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13065 | AUTH_SYNC, |
| 13066 | OK, |
| 13067 | kSecureServer, |
| 13068 | AUTH_NONE, |
| 13069 | OK, |
| 13070 | 2, |
| 13071 | 1, |
| 13072 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13073 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13074 | {__LINE__, |
| 13075 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13076 | AUTH_SYNC, |
| 13077 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13078 | kSecureServer, |
| 13079 | AUTH_NONE, |
| 13080 | OK, |
| 13081 | 2, |
| 13082 | kNoSSL, |
| 13083 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13084 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13085 | {__LINE__, |
| 13086 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13087 | AUTH_SYNC, |
| 13088 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13089 | kSecureServer, |
| 13090 | AUTH_NONE, |
| 13091 | OK, |
| 13092 | 2, |
| 13093 | kNoSSL, |
| 13094 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13095 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13096 | {__LINE__, |
| 13097 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13098 | AUTH_SYNC, |
| 13099 | ERR_UNEXPECTED, |
| 13100 | kSecureServer, |
| 13101 | AUTH_NONE, |
| 13102 | OK, |
| 13103 | 2, |
| 13104 | kNoSSL, |
| 13105 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13106 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13107 | {__LINE__, |
| 13108 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13109 | AUTH_ASYNC, |
| 13110 | OK, |
| 13111 | kSecureServer, |
| 13112 | AUTH_NONE, |
| 13113 | OK, |
| 13114 | 2, |
| 13115 | 1, |
| 13116 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13117 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13118 | {__LINE__, |
| 13119 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13120 | AUTH_ASYNC, |
| 13121 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13122 | kSecureServer, |
| 13123 | AUTH_NONE, |
| 13124 | OK, |
| 13125 | 2, |
| 13126 | kNoSSL, |
| 13127 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13128 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13129 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13130 | {__LINE__, |
| 13131 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13132 | AUTH_SYNC, |
| 13133 | OK, |
| 13134 | kSecureServer, |
| 13135 | AUTH_SYNC, |
| 13136 | OK, |
| 13137 | 3, |
| 13138 | 1, |
| 13139 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13140 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13141 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13142 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13143 | {__LINE__, |
| 13144 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13145 | AUTH_SYNC, |
| 13146 | OK, |
| 13147 | kSecureServer, |
| 13148 | AUTH_SYNC, |
| 13149 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13150 | 3, |
| 13151 | 1, |
| 13152 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13153 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13154 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13155 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13156 | {__LINE__, |
| 13157 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13158 | AUTH_ASYNC, |
| 13159 | OK, |
| 13160 | kSecureServer, |
| 13161 | AUTH_SYNC, |
| 13162 | OK, |
| 13163 | 3, |
| 13164 | 1, |
| 13165 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13166 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13167 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13168 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13169 | {__LINE__, |
| 13170 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13171 | AUTH_ASYNC, |
| 13172 | OK, |
| 13173 | kSecureServer, |
| 13174 | AUTH_SYNC, |
| 13175 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13176 | 3, |
| 13177 | 1, |
| 13178 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13179 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13180 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13181 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13182 | {__LINE__, |
| 13183 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13184 | AUTH_SYNC, |
| 13185 | OK, |
| 13186 | kSecureServer, |
| 13187 | AUTH_ASYNC, |
| 13188 | OK, |
| 13189 | 3, |
| 13190 | 1, |
| 13191 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13192 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13193 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13194 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13195 | {__LINE__, |
| 13196 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13197 | AUTH_SYNC, |
| 13198 | OK, |
| 13199 | kSecureServer, |
| 13200 | AUTH_ASYNC, |
| 13201 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13202 | 3, |
| 13203 | 1, |
| 13204 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13205 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13206 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13207 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13208 | {__LINE__, |
| 13209 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13210 | AUTH_ASYNC, |
| 13211 | OK, |
| 13212 | kSecureServer, |
| 13213 | AUTH_ASYNC, |
| 13214 | OK, |
| 13215 | 3, |
| 13216 | 1, |
| 13217 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13218 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13219 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13220 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13221 | {__LINE__, |
| 13222 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13223 | AUTH_ASYNC, |
| 13224 | OK, |
| 13225 | kSecureServer, |
| 13226 | AUTH_ASYNC, |
| 13227 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13228 | 3, |
| 13229 | 1, |
| 13230 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13231 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13232 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13233 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13234 | {__LINE__, |
| 13235 | kProxy, |
| 13236 | AUTH_ASYNC, |
| 13237 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13238 | kSecureServer, |
| 13239 | AUTH_ASYNC, |
| 13240 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13241 | 4, |
| 13242 | 2, |
| 13243 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13244 | TestRound(kConnect, kProxyChallenge, OK), |
| 13245 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13246 | &kServerChallenge), |
| 13247 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13248 | }; |
| 13249 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13250 | for (const auto& test_config : test_configs) { |
| 13251 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13252 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13253 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13254 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13255 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13256 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13257 | |
| 13258 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13259 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13260 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13261 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13262 | std::string auth_challenge = "Mock realm=proxy"; |
| 13263 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13264 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13265 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13266 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13267 | empty_ssl_info, origin, |
| 13268 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13269 | auth_handler->SetGenerateExpectation( |
| 13270 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13271 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13272 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13273 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13274 | } |
| 13275 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13276 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13277 | std::string auth_challenge = "Mock realm=server"; |
| 13278 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13279 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13280 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13281 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13282 | empty_ssl_info, origin, |
| 13283 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13284 | auth_handler->SetGenerateExpectation( |
| 13285 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13286 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13287 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13288 | |
| 13289 | // The second handler always succeeds. It should only be used where there |
| 13290 | // are multiple auth sessions for server auth in the same network |
| 13291 | // transaction using the same auth scheme. |
| 13292 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13293 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13294 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13295 | empty_ssl_info, origin, |
| 13296 | NetLogWithSource()); |
| 13297 | second_handler->SetGenerateExpectation(true, OK); |
| 13298 | auth_factory->AddMockHandler(second_handler.release(), |
| 13299 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13300 | } |
| 13301 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13302 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13303 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13304 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13305 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13306 | session_deps_.proxy_resolution_service = |
| 13307 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13308 | } |
| 13309 | |
| 13310 | HttpRequestInfo request; |
| 13311 | request.method = "GET"; |
| 13312 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13313 | request.traffic_annotation = |
| 13314 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13315 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13317 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13318 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13319 | |
| 13320 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13321 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13322 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13323 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13324 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13325 | |
| 13326 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13327 | mock_reads.back().push_back(read_write_round.read); |
| 13328 | mock_writes.back().push_back(read_write_round.write); |
| 13329 | |
| 13330 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13331 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13332 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13333 | mock_reads.push_back(std::vector<MockRead>()); |
| 13334 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13335 | } |
| 13336 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13337 | if (read_write_round.extra_read) { |
| 13338 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13339 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13340 | if (read_write_round.extra_write) { |
| 13341 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13342 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13343 | |
| 13344 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13345 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13346 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13347 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13348 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13350 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13351 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13352 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13353 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13354 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13355 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13356 | } |
| 13357 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13358 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13359 | // they are as well. |
| 13360 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13361 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13362 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13363 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13364 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13365 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13366 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13367 | int rv; |
| 13368 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13369 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13370 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13371 | rv = trans.RestartWithAuth( |
| 13372 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13373 | } |
| 13374 | if (rv == ERR_IO_PENDING) |
| 13375 | rv = callback.WaitForResult(); |
| 13376 | |
| 13377 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13378 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13379 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13380 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13381 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13382 | continue; |
| 13383 | } |
| 13384 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13385 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13386 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13387 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13388 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13389 | } |
| 13390 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13391 | } |
| 13392 | } |
| 13393 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13394 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13395 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13396 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13397 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13398 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13399 | session_deps_.proxy_resolution_service = |
| 13400 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13401 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13402 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13403 | |
| 13404 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13405 | auth_handler->set_connection_based(true); |
| 13406 | std::string auth_challenge = "Mock realm=server"; |
| 13407 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13408 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13409 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13410 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13411 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13412 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13413 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13414 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13415 | int rv = OK; |
| 13416 | const HttpResponseInfo* response = NULL; |
| 13417 | HttpRequestInfo request; |
| 13418 | request.method = "GET"; |
| 13419 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13420 | request.traffic_annotation = |
| 13421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13422 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13423 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13424 | |
| 13425 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13426 | // to validate that the TCP socket is not released to the pool between |
| 13427 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13428 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13429 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13430 | 50, // Max sockets for pool |
| 13431 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13432 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13433 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13434 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13435 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13436 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13439 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13440 | |
| 13441 | const MockWrite kGet( |
| 13442 | "GET / HTTP/1.1\r\n" |
| 13443 | "Host: www.example.com\r\n" |
| 13444 | "Connection: keep-alive\r\n\r\n"); |
| 13445 | const MockWrite kGetAuth( |
| 13446 | "GET / HTTP/1.1\r\n" |
| 13447 | "Host: www.example.com\r\n" |
| 13448 | "Connection: keep-alive\r\n" |
| 13449 | "Authorization: auth_token\r\n\r\n"); |
| 13450 | |
| 13451 | const MockRead kServerChallenge( |
| 13452 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13453 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13454 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13455 | "Content-Length: 14\r\n\r\n" |
| 13456 | "Unauthorized\r\n"); |
| 13457 | const MockRead kSuccess( |
| 13458 | "HTTP/1.1 200 OK\r\n" |
| 13459 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13460 | "Content-Length: 3\r\n\r\n" |
| 13461 | "Yes"); |
| 13462 | |
| 13463 | MockWrite writes[] = { |
| 13464 | // First round |
| 13465 | kGet, |
| 13466 | // Second round |
| 13467 | kGetAuth, |
| 13468 | // Third round |
| 13469 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13470 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13471 | kGetAuth, |
| 13472 | // Competing request |
| 13473 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13474 | }; |
| 13475 | MockRead reads[] = { |
| 13476 | // First round |
| 13477 | kServerChallenge, |
| 13478 | // Second round |
| 13479 | kServerChallenge, |
| 13480 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13481 | kServerChallenge, |
| 13482 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13483 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13484 | // Competing response |
| 13485 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13486 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13487 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13488 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13489 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13490 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13491 | |
| 13492 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13493 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13494 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13495 | if (rv == ERR_IO_PENDING) |
| 13496 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13497 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13498 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13499 | ASSERT_TRUE(response); |
| 13500 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13501 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13502 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13503 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13504 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13505 | // In between rounds, another request comes in for the same domain. |
| 13506 | // It should not be able to grab the TCP socket that trans has already |
| 13507 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13508 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13509 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13510 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13511 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13512 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13513 | // callback_compete.WaitForResult at this point would stall forever, |
| 13514 | // since the HttpNetworkTransaction does not release the request back to |
| 13515 | // the pool until after authentication completes. |
| 13516 | |
| 13517 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13518 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13519 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13520 | if (rv == ERR_IO_PENDING) |
| 13521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13522 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13523 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13524 | ASSERT_TRUE(response); |
| 13525 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13526 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13527 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13528 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13529 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13530 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13531 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13532 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13533 | if (rv == ERR_IO_PENDING) |
| 13534 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13535 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13536 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13537 | ASSERT_TRUE(response); |
| 13538 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13539 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13540 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13541 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13542 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13543 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13544 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13545 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13546 | if (rv == ERR_IO_PENDING) |
| 13547 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13548 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13549 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13550 | ASSERT_TRUE(response); |
| 13551 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13552 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13553 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13554 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13555 | // auth handler should transition to a DONE state in concert with the remote |
| 13556 | // server. But that's not something we can test here with a mock handler. |
| 13557 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13558 | auth_handler->state()); |
| 13559 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13560 | // Read the body since the fourth round was successful. This will also |
| 13561 | // release the socket back to the pool. |
| 13562 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13563 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13564 | if (rv == ERR_IO_PENDING) |
| 13565 | rv = callback.WaitForResult(); |
| 13566 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13567 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13568 | EXPECT_EQ(0, rv); |
| 13569 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13570 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13571 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13572 | |
| 13573 | // The competing request can now finish. Wait for the headers and then |
| 13574 | // read the body. |
| 13575 | rv = callback_compete.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 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13578 | if (rv == ERR_IO_PENDING) |
| 13579 | rv = callback.WaitForResult(); |
| 13580 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13581 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13582 | EXPECT_EQ(0, rv); |
| 13583 | |
| 13584 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13585 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13586 | } |
| 13587 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13588 | // This tests the case that a request is issued via http instead of spdy after |
| 13589 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13590 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13591 | HttpRequestInfo request; |
| 13592 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13593 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13594 | request.traffic_annotation = |
| 13595 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13596 | |
| 13597 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13598 | MockWrite( |
| 13599 | "GET / HTTP/1.1\r\n" |
| 13600 | "Host: www.example.org\r\n" |
| 13601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13602 | }; |
| 13603 | |
| 13604 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13605 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13606 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13607 | MockRead("\r\n"), |
| 13608 | MockRead("hello world"), |
| 13609 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13610 | }; |
| 13611 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13612 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13613 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13614 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13615 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13616 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13617 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13620 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13621 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13622 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13623 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13625 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13626 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13628 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13630 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13631 | ASSERT_TRUE(response); |
| 13632 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13633 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13634 | |
| 13635 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13636 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13637 | EXPECT_EQ("hello world", response_data); |
| 13638 | |
| 13639 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13640 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13641 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13642 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13643 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13644 | // immediate server closing of the socket. |
| 13645 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13646 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13647 | HttpRequestInfo request; |
| 13648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13649 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13650 | request.traffic_annotation = |
| 13651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13652 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13653 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13654 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13656 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 13657 | spdy::SpdySerializedFrame req( |
| 13658 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13659 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13660 | |
| 13661 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13662 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13663 | }; |
| 13664 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13665 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13666 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13668 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13673 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13675 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13676 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13677 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13678 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13679 | // it gets it. This is needed since the auth handler may get destroyed |
| 13680 | // before we get a chance to query it. |
| 13681 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13682 | public: |
| 13683 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13684 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13685 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13686 | |
| 13687 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13688 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13689 | const HttpRequestInfo* request, |
| 13690 | const CompletionCallback& callback, |
| 13691 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13692 | *url_ = request->url; |
| 13693 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13694 | credentials, request, callback, auth_token); |
| 13695 | } |
| 13696 | |
| 13697 | private: |
| 13698 | GURL* url_; |
| 13699 | }; |
| 13700 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13701 | // Test that if we cancel the transaction as the connection is completing, that |
| 13702 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13703 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13704 | // Setup everything about the connection to complete synchronously, so that |
| 13705 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13706 | // for is the callback from the HttpStreamRequest. |
| 13707 | // Then cancel the transaction. |
| 13708 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13709 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13710 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13711 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13712 | MockRead(SYNCHRONOUS, "hello world"), |
| 13713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13714 | }; |
| 13715 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13716 | HttpRequestInfo request; |
| 13717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13718 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13719 | request.traffic_annotation = |
| 13720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13721 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13722 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13724 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13725 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13726 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13727 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13728 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13731 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13732 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13733 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13734 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13736 | trans.reset(); // Cancel the transaction here. |
| 13737 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13738 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13739 | } |
| 13740 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13741 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13742 | // stream is drained properly and added back to the socket pool. The main |
| 13743 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13744 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13745 | // deleted. |
| 13746 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13747 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13748 | MockRead data_reads[] = { |
| 13749 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13750 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13751 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13752 | MockRead(ASYNC, "1"), |
| 13753 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13754 | // HttpNetworkTransaction has been deleted. |
| 13755 | MockRead(ASYNC, "2"), |
| 13756 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13757 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13758 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13762 | |
| 13763 | { |
| 13764 | HttpRequestInfo request; |
| 13765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13766 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13767 | request.traffic_annotation = |
| 13768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13769 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13771 | TestCompletionCallback callback; |
| 13772 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13773 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13774 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13775 | callback.WaitForResult(); |
| 13776 | |
| 13777 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13778 | ASSERT_TRUE(response); |
| 13779 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13780 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13781 | |
| 13782 | // The transaction and HttpRequestInfo are deleted. |
| 13783 | } |
| 13784 | |
| 13785 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13786 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13787 | |
| 13788 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13789 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13790 | } |
| 13791 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13792 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13793 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13794 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13795 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13796 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13797 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13798 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13800 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13801 | HttpRequestInfo request; |
| 13802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13803 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13804 | request.traffic_annotation = |
| 13805 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13806 | |
| 13807 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13808 | MockWrite( |
| 13809 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13810 | "Host: www.example.org\r\n" |
| 13811 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13812 | }; |
| 13813 | |
| 13814 | MockRead data_reads1[] = { |
| 13815 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13816 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13817 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13819 | }; |
| 13820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13821 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13822 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13824 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13826 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13827 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13828 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13829 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13830 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13832 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13834 | |
| 13835 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13838 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13839 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13840 | |
| 13841 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13842 | EXPECT_EQ(200, response->headers->response_code()); |
| 13843 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13844 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13845 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13846 | HostPortPair::FromString("myproxy:70")), |
| 13847 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13848 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13849 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13850 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13851 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13852 | |
| 13853 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13854 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13855 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13856 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13857 | } |
| 13858 | |
| 13859 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13860 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13861 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13862 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13863 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13864 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13865 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13867 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13868 | HttpRequestInfo request; |
| 13869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13870 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13871 | request.traffic_annotation = |
| 13872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13873 | |
| 13874 | // Since we have proxy, should try to establish tunnel. |
| 13875 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13876 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13877 | "Host: www.example.org:443\r\n" |
| 13878 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13879 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13880 | MockWrite("GET / HTTP/1.1\r\n" |
| 13881 | "Host: www.example.org\r\n" |
| 13882 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13883 | }; |
| 13884 | |
| 13885 | MockRead data_reads1[] = { |
| 13886 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13887 | |
| 13888 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13889 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13890 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13891 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13892 | }; |
| 13893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13894 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13896 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13899 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13902 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13903 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13904 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13905 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13907 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13909 | |
| 13910 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13911 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13912 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13913 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13914 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13915 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13916 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13917 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13918 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13919 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13920 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13922 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13923 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13924 | |
| 13925 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13926 | EXPECT_EQ(200, response->headers->response_code()); |
| 13927 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13928 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13929 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13930 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13931 | HostPortPair::FromString("myproxy:70")), |
| 13932 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13933 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13934 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13935 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13936 | |
| 13937 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13938 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13939 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13940 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13941 | } |
| 13942 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13943 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13944 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13945 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13946 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13947 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13948 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13949 | BoundTestNetLog log; |
| 13950 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13952 | |
| 13953 | HttpRequestInfo request; |
| 13954 | request.method = "GET"; |
| 13955 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13956 | request.traffic_annotation = |
| 13957 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13958 | |
| 13959 | // Since we have proxy, should try to establish tunnel. |
| 13960 | MockWrite data_writes1[] = { |
| 13961 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13962 | "Host: [::1]:443\r\n" |
| 13963 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13964 | |
| 13965 | MockWrite("GET / HTTP/1.1\r\n" |
| 13966 | "Host: [::1]\r\n" |
| 13967 | "Connection: keep-alive\r\n\r\n"), |
| 13968 | }; |
| 13969 | |
| 13970 | MockRead data_reads1[] = { |
| 13971 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13972 | |
| 13973 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13974 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13975 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13976 | MockRead(SYNCHRONOUS, OK), |
| 13977 | }; |
| 13978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13979 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13980 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13981 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13982 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13983 | |
| 13984 | TestCompletionCallback callback1; |
| 13985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13988 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13989 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13990 | |
| 13991 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13992 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13993 | TestNetLogEntry::List entries; |
| 13994 | log.GetEntries(&entries); |
| 13995 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13996 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13997 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13998 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13999 | entries, pos, |
| 14000 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14001 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14003 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14004 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14005 | |
| 14006 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14007 | EXPECT_EQ(200, response->headers->response_code()); |
| 14008 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14009 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14010 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14011 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14012 | HostPortPair::FromString("myproxy:70")), |
| 14013 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14014 | |
| 14015 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14016 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14017 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14018 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14019 | } |
| 14020 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14021 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14022 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14023 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14024 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14025 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14026 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14027 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14029 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14030 | HttpRequestInfo request; |
| 14031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14032 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14033 | request.traffic_annotation = |
| 14034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14035 | |
| 14036 | // Since we have proxy, should try to establish tunnel. |
| 14037 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14038 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14039 | "Host: www.example.org:443\r\n" |
| 14040 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14041 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14042 | MockWrite("GET / HTTP/1.1\r\n" |
| 14043 | "Host: www.example.org\r\n" |
| 14044 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14045 | }; |
| 14046 | |
| 14047 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14048 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14049 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14050 | }; |
| 14051 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14052 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14054 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14056 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14057 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14059 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14061 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14063 | |
| 14064 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14065 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14066 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14067 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14068 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14069 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14070 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14071 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14072 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14073 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14074 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14075 | } |
| 14076 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14077 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14078 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14079 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14080 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14081 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14082 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14083 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14084 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14085 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14086 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14087 | }; |
| 14088 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14089 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14090 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14091 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14092 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14093 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14095 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14096 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14097 | |
| 14098 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14099 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14100 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14101 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14102 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14103 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14104 | |
| 14105 | HttpRequestInfo request; |
| 14106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14107 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14108 | request.traffic_annotation = |
| 14109 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14111 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14112 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14113 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14114 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14116 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14117 | } |
| 14118 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14119 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14120 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14121 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14122 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14123 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14124 | request_info.url = GURL("https://www.example.com/"); |
| 14125 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14126 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14127 | request_info.traffic_annotation = |
| 14128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14129 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14130 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14131 | MockWrite data_writes[] = { |
| 14132 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14133 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14134 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14136 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14137 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14138 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14140 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14141 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14142 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14143 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14144 | rv = callback.WaitForResult(); |
| 14145 | ASSERT_EQ(error, rv); |
| 14146 | } |
| 14147 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14148 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14149 | // Just check a grab bag of cert errors. |
| 14150 | static const int kErrors[] = { |
| 14151 | ERR_CERT_COMMON_NAME_INVALID, |
| 14152 | ERR_CERT_AUTHORITY_INVALID, |
| 14153 | ERR_CERT_DATE_INVALID, |
| 14154 | }; |
| 14155 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14156 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14157 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14158 | } |
| 14159 | } |
| 14160 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14161 | // Ensure that a client certificate is removed from the SSL client auth |
| 14162 | // cache when: |
| 14163 | // 1) No proxy is involved. |
| 14164 | // 2) TLS False Start is disabled. |
| 14165 | // 3) The initial TLS handshake requests a client certificate. |
| 14166 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14167 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14168 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14169 | request_info.url = GURL("https://www.example.com/"); |
| 14170 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14171 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14172 | request_info.traffic_annotation = |
| 14173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14174 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14175 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14176 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14177 | |
| 14178 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14179 | // CertificateRequest is received for the first time, the handshake will |
| 14180 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14181 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14182 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14184 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14186 | |
| 14187 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14188 | // False Start is not being used, the result of the SSL handshake will be |
| 14189 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14190 | // matches the result of a server sending a handshake_failure alert, |
| 14191 | // rather than a Finished message, because it requires a client |
| 14192 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14193 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14194 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14195 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14196 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14197 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14198 | |
| 14199 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14200 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14201 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14202 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14203 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14204 | // requiring a client certificate, this fallback handshake should also |
| 14205 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14206 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14207 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14208 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14209 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14210 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14211 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14212 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14213 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14214 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14215 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14216 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14217 | // requiring a client certificate, this fallback handshake should also |
| 14218 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14219 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14220 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14222 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14223 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14227 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14228 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14229 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14230 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14231 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14232 | |
| 14233 | // Complete the SSL handshake, which should abort due to requiring a |
| 14234 | // client certificate. |
| 14235 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14236 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14237 | |
| 14238 | // Indicate that no certificate should be supplied. From the perspective |
| 14239 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14240 | // certificate, so this is the same as supply a |
| 14241 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14242 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14243 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14244 | |
| 14245 | // Ensure the certificate was added to the client auth cache before |
| 14246 | // allowing the connection to continue restarting. |
| 14247 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14248 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14249 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14250 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14251 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14252 | |
| 14253 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14254 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14255 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14256 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14257 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14258 | |
| 14259 | // Ensure that the client certificate is removed from the cache on a |
| 14260 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14261 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14262 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14263 | } |
| 14264 | |
| 14265 | // Ensure that a client certificate is removed from the SSL client auth |
| 14266 | // cache when: |
| 14267 | // 1) No proxy is involved. |
| 14268 | // 2) TLS False Start is enabled. |
| 14269 | // 3) The initial TLS handshake requests a client certificate. |
| 14270 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14271 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14272 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14273 | request_info.url = GURL("https://www.example.com/"); |
| 14274 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14275 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14276 | request_info.traffic_annotation = |
| 14277 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14278 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14279 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14280 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14281 | |
| 14282 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14283 | // return successfully after reading up to the peer's Certificate message. |
| 14284 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14285 | // enqueue application data to be sent in the same packet as the |
| 14286 | // ChangeCipherSpec and Finished messages. |
| 14287 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14288 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14289 | // Finished messages. If there was an error negotiating with the peer, |
| 14290 | // such as due to the peer requiring a client certificate when none was |
| 14291 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14292 | // called. |
| 14293 | |
| 14294 | // Like the non-False Start case, when a client certificate is requested by |
| 14295 | // the peer, the handshake is aborted during the Connect() call. |
| 14296 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14297 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14298 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14300 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14301 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14302 | |
| 14303 | // When a client certificate is supplied, Connect() will not be aborted |
| 14304 | // when the peer requests the certificate. Instead, the handshake will |
| 14305 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14306 | // the socket. The handshake messages are not processed until Read() is |
| 14307 | // called, which then detects that the handshake was aborted, due to the |
| 14308 | // peer sending a handshake_failure because it requires a client |
| 14309 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14310 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14311 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14313 | MockRead data2_reads[] = { |
| 14314 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14315 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14316 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14317 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14318 | |
| 14319 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14320 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14321 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14322 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14323 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14325 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14326 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14327 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14328 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14329 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14330 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14331 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14332 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14333 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14334 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14335 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14336 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14337 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14338 | ssl_data5.cert_request_info = cert_request.get(); |
| 14339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14340 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14341 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14342 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14343 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14345 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14346 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14347 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14348 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14349 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14350 | |
| 14351 | // Complete the SSL handshake, which should abort due to requiring a |
| 14352 | // client certificate. |
| 14353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14354 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14355 | |
| 14356 | // Indicate that no certificate should be supplied. From the perspective |
| 14357 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14358 | // certificate, so this is the same as supply a |
| 14359 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14360 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14361 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14362 | |
| 14363 | // Ensure the certificate was added to the client auth cache before |
| 14364 | // allowing the connection to continue restarting. |
| 14365 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14366 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14367 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14368 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14369 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14370 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14371 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14372 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14373 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14374 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14375 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14376 | |
| 14377 | // Ensure that the client certificate is removed from the cache on a |
| 14378 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14379 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14380 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14381 | } |
| 14382 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14383 | // Ensure that a client certificate is removed from the SSL client auth |
| 14384 | // cache when: |
| 14385 | // 1) An HTTPS proxy is involved. |
| 14386 | // 3) The HTTPS proxy requests a client certificate. |
| 14387 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14388 | // proxy. |
| 14389 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14390 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14391 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14392 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14393 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14394 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14395 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14396 | |
| 14397 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14398 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14399 | |
| 14400 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14401 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14402 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14403 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14404 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14405 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14407 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14408 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14409 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14410 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14411 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14413 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14415 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14416 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14417 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14418 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14419 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14421 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14422 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14423 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14424 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14425 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14426 | requests[0].url = GURL("https://www.example.com/"); |
| 14427 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14428 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14429 | requests[0].traffic_annotation = |
| 14430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14431 | |
| 14432 | requests[1].url = GURL("http://www.example.com/"); |
| 14433 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14434 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14435 | requests[1].traffic_annotation = |
| 14436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14437 | |
| 14438 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14439 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14442 | |
| 14443 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14444 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14445 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14446 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14447 | |
| 14448 | // Complete the SSL handshake, which should abort due to requiring a |
| 14449 | // client certificate. |
| 14450 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14451 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14452 | |
| 14453 | // Indicate that no certificate should be supplied. From the perspective |
| 14454 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14455 | // certificate, so this is the same as supply a |
| 14456 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14457 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14458 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14459 | |
| 14460 | // Ensure the certificate was added to the client auth cache before |
| 14461 | // allowing the connection to continue restarting. |
| 14462 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14463 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14464 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14465 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14466 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14467 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14468 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14469 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14470 | HostPortPair("www.example.com", 443), &client_cert, |
| 14471 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14472 | |
| 14473 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14474 | // then consume ssl_data3, which should also fail. The result code is |
| 14475 | // checked against what ssl_data3 should return. |
| 14476 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14477 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14478 | |
| 14479 | // Now that the new handshake has failed, ensure that the client |
| 14480 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14481 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14482 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14483 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14484 | HostPortPair("www.example.com", 443), &client_cert, |
| 14485 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14486 | } |
| 14487 | } |
| 14488 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14489 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14490 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14491 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14493 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14494 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14495 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14496 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14497 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14498 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14499 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14500 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14501 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14502 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14503 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14504 | spdy::SpdySerializedFrame host1_resp( |
| 14505 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14506 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14507 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14508 | spdy::SpdySerializedFrame host2_resp( |
| 14509 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14510 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14511 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14512 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14513 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14514 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14515 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14516 | }; |
| 14517 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14518 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14519 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14520 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14521 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14522 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14523 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14524 | HttpRequestInfo request1; |
| 14525 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14526 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14527 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14528 | request1.traffic_annotation = |
| 14529 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14530 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14531 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14532 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14534 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14535 | |
| 14536 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14537 | ASSERT_TRUE(response); |
| 14538 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14539 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14540 | |
| 14541 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14542 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14543 | EXPECT_EQ("hello!", response_data); |
| 14544 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14545 | // Preload mail.example.com into HostCache. |
| 14546 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14547 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14548 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14549 | std::unique_ptr<HostResolver::Request> request; |
| 14550 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14551 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14552 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14554 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14556 | |
| 14557 | HttpRequestInfo request2; |
| 14558 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14559 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14560 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14561 | request2.traffic_annotation = |
| 14562 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14563 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14565 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14567 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14568 | |
| 14569 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14570 | ASSERT_TRUE(response); |
| 14571 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14572 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14573 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14574 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14575 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14576 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14577 | } |
| 14578 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14579 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14580 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14581 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14583 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14584 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14585 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14586 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14587 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14588 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14589 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14590 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14591 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14592 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14593 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14594 | spdy::SpdySerializedFrame host1_resp( |
| 14595 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14596 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14597 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14598 | spdy::SpdySerializedFrame host2_resp( |
| 14599 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14600 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14601 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14602 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14603 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14604 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14605 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14606 | }; |
| 14607 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14608 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14609 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14610 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14611 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14612 | |
| 14613 | TestCompletionCallback callback; |
| 14614 | HttpRequestInfo request1; |
| 14615 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14616 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14617 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14618 | request1.traffic_annotation = |
| 14619 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14620 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14622 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14624 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14625 | |
| 14626 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14627 | ASSERT_TRUE(response); |
| 14628 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14629 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14630 | |
| 14631 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14632 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14633 | EXPECT_EQ("hello!", response_data); |
| 14634 | |
| 14635 | HttpRequestInfo request2; |
| 14636 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14637 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14638 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14639 | request2.traffic_annotation = |
| 14640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14641 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14643 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14645 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14646 | |
| 14647 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14648 | ASSERT_TRUE(response); |
| 14649 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14650 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14651 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14652 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14653 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14654 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14655 | } |
| 14656 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14657 | // Regression test for https://crbug.com/546991. |
| 14658 | // The server might not be able to serve an IP pooled request, and might send a |
| 14659 | // 421 Misdirected Request response status to indicate this. |
| 14660 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14661 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14662 | // Two hosts resolve to the same IP address. |
| 14663 | const std::string ip_addr = "1.2.3.4"; |
| 14664 | IPAddress ip; |
| 14665 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14666 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14667 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14668 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14669 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14670 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14671 | |
| 14672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14673 | |
| 14674 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14675 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14676 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14677 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14678 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14679 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14680 | spdy::SpdySerializedFrame rst( |
| 14681 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14682 | MockWrite writes1[] = { |
| 14683 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14684 | CreateMockWrite(rst, 6), |
| 14685 | }; |
| 14686 | |
| 14687 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14688 | spdy::SpdySerializedFrame resp1( |
| 14689 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14690 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14691 | spdy::SpdyHeaderBlock response_headers; |
| 14692 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14693 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14694 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14695 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14696 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14697 | |
| 14698 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14699 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14700 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14701 | |
| 14702 | AddSSLSocketData(); |
| 14703 | |
| 14704 | // Retry the second request on a second connection. |
| 14705 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14706 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14707 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14708 | MockWrite writes2[] = { |
| 14709 | CreateMockWrite(req3, 0), |
| 14710 | }; |
| 14711 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14712 | spdy::SpdySerializedFrame resp3( |
| 14713 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14714 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14715 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14716 | MockRead(ASYNC, 0, 3)}; |
| 14717 | |
| 14718 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14719 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14720 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14721 | |
| 14722 | AddSSLSocketData(); |
| 14723 | |
| 14724 | // Preload mail.example.org into HostCache. |
| 14725 | HostPortPair host_port("mail.example.org", 443); |
| 14726 | HostResolver::RequestInfo resolve_info(host_port); |
| 14727 | AddressList ignored; |
| 14728 | std::unique_ptr<HostResolver::Request> request; |
| 14729 | TestCompletionCallback callback; |
| 14730 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14731 | &ignored, callback.callback(), |
| 14732 | &request, NetLogWithSource()); |
| 14733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14734 | rv = callback.WaitForResult(); |
| 14735 | EXPECT_THAT(rv, IsOk()); |
| 14736 | |
| 14737 | HttpRequestInfo request1; |
| 14738 | request1.method = "GET"; |
| 14739 | request1.url = GURL("https://www.example.org/"); |
| 14740 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14741 | request1.traffic_annotation = |
| 14742 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14743 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14744 | |
| 14745 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14747 | rv = callback.WaitForResult(); |
| 14748 | EXPECT_THAT(rv, IsOk()); |
| 14749 | |
| 14750 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14751 | ASSERT_TRUE(response); |
| 14752 | ASSERT_TRUE(response->headers); |
| 14753 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14754 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14755 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14756 | std::string response_data; |
| 14757 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14758 | EXPECT_EQ("hello!", response_data); |
| 14759 | |
| 14760 | HttpRequestInfo request2; |
| 14761 | request2.method = "GET"; |
| 14762 | request2.url = GURL("https://mail.example.org/"); |
| 14763 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14764 | request2.traffic_annotation = |
| 14765 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14766 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14767 | |
| 14768 | BoundTestNetLog log; |
| 14769 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14770 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14771 | rv = callback.WaitForResult(); |
| 14772 | EXPECT_THAT(rv, IsOk()); |
| 14773 | |
| 14774 | response = trans2.GetResponseInfo(); |
| 14775 | ASSERT_TRUE(response); |
| 14776 | ASSERT_TRUE(response->headers); |
| 14777 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14778 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14779 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14780 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14781 | EXPECT_EQ("hello!", response_data); |
| 14782 | |
| 14783 | TestNetLogEntry::List entries; |
| 14784 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14785 | ExpectLogContainsSomewhere( |
| 14786 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14787 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14788 | } |
| 14789 | |
| 14790 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14791 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14792 | // portions of the response. |
| 14793 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14794 | // Two hosts resolve to the same IP address. |
| 14795 | const std::string ip_addr = "1.2.3.4"; |
| 14796 | IPAddress ip; |
| 14797 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14798 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14799 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14800 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14801 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14802 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14803 | |
| 14804 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14805 | |
| 14806 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14807 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14808 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14809 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14810 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14811 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14812 | spdy::SpdySerializedFrame rst( |
| 14813 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14814 | MockWrite writes1[] = { |
| 14815 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14816 | CreateMockWrite(rst, 6), |
| 14817 | }; |
| 14818 | |
| 14819 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14820 | spdy::SpdySerializedFrame resp1( |
| 14821 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14822 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14823 | spdy::SpdyHeaderBlock response_headers; |
| 14824 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14825 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14826 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14827 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14828 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14829 | |
| 14830 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14831 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14832 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14833 | |
| 14834 | AddSSLSocketData(); |
| 14835 | |
| 14836 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14837 | // Retry again. |
| 14838 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14839 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14840 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14841 | MockWrite writes2[] = { |
| 14842 | CreateMockWrite(req3, 0), |
| 14843 | }; |
| 14844 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14845 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14846 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14847 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14848 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14849 | MockRead(ASYNC, 0, 3)}; |
| 14850 | |
| 14851 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14852 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14853 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14854 | |
| 14855 | AddSSLSocketData(); |
| 14856 | |
| 14857 | // Preload mail.example.org into HostCache. |
| 14858 | HostPortPair host_port("mail.example.org", 443); |
| 14859 | HostResolver::RequestInfo resolve_info(host_port); |
| 14860 | AddressList ignored; |
| 14861 | std::unique_ptr<HostResolver::Request> request; |
| 14862 | TestCompletionCallback callback; |
| 14863 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14864 | &ignored, callback.callback(), |
| 14865 | &request, NetLogWithSource()); |
| 14866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14867 | rv = callback.WaitForResult(); |
| 14868 | EXPECT_THAT(rv, IsOk()); |
| 14869 | |
| 14870 | HttpRequestInfo request1; |
| 14871 | request1.method = "GET"; |
| 14872 | request1.url = GURL("https://www.example.org/"); |
| 14873 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14874 | request1.traffic_annotation = |
| 14875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14876 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14877 | |
| 14878 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14880 | rv = callback.WaitForResult(); |
| 14881 | EXPECT_THAT(rv, IsOk()); |
| 14882 | |
| 14883 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14884 | ASSERT_TRUE(response); |
| 14885 | ASSERT_TRUE(response->headers); |
| 14886 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14887 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14888 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14889 | std::string response_data; |
| 14890 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14891 | EXPECT_EQ("hello!", response_data); |
| 14892 | |
| 14893 | HttpRequestInfo request2; |
| 14894 | request2.method = "GET"; |
| 14895 | request2.url = GURL("https://mail.example.org/"); |
| 14896 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14897 | request2.traffic_annotation = |
| 14898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14899 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14900 | |
| 14901 | BoundTestNetLog log; |
| 14902 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14904 | rv = callback.WaitForResult(); |
| 14905 | EXPECT_THAT(rv, IsOk()); |
| 14906 | |
| 14907 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14908 | // caller. |
| 14909 | response = trans2.GetResponseInfo(); |
| 14910 | ASSERT_TRUE(response); |
| 14911 | ASSERT_TRUE(response->headers); |
| 14912 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14913 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14914 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14915 | EXPECT_TRUE(response->ssl_info.cert); |
| 14916 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14917 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14918 | } |
| 14919 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14920 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14921 | public: |
| 14922 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14923 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14924 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14925 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14926 | int ResolveFromCache(const RequestInfo& info, |
| 14927 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14928 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14929 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14930 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14931 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14932 | return rv; |
| 14933 | } |
| 14934 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14935 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14936 | const HostPortPair host_port_; |
| 14937 | }; |
| 14938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14939 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14940 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14941 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14942 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14943 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14945 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14946 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14947 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14948 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14949 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14950 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14951 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14952 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14953 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14954 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14955 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14956 | spdy::SpdySerializedFrame host1_resp( |
| 14957 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14958 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14959 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 14960 | spdy::SpdySerializedFrame host2_resp( |
| 14961 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14962 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14963 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14964 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14965 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14966 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14967 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14968 | }; |
| 14969 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14970 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14971 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14972 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14973 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14974 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14975 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14976 | HttpRequestInfo request1; |
| 14977 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14978 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14979 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14980 | request1.traffic_annotation = |
| 14981 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14982 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14984 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14986 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14987 | |
| 14988 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14989 | ASSERT_TRUE(response); |
| 14990 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14991 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14992 | |
| 14993 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14994 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14995 | EXPECT_EQ("hello!", response_data); |
| 14996 | |
| 14997 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14998 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14999 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15000 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15001 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15002 | &ignored, callback.callback(), |
| 15003 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15007 | |
| 15008 | HttpRequestInfo request2; |
| 15009 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15010 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15011 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15012 | request2.traffic_annotation = |
| 15013 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15014 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15015 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15016 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15018 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15019 | |
| 15020 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15021 | ASSERT_TRUE(response); |
| 15022 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15023 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15024 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15025 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15026 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15027 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15028 | } |
| 15029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15030 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15031 | const std::string https_url = "https://www.example.org:8080/"; |
| 15032 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15033 | |
| 15034 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15035 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15036 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15037 | |
| 15038 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15039 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15040 | }; |
| 15041 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15042 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15043 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15044 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15045 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15046 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15047 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15048 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15049 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15050 | |
| 15051 | // HTTP GET for the HTTP URL |
| 15052 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15053 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15054 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15055 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15056 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15057 | }; |
| 15058 | |
| 15059 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15060 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15061 | MockRead(ASYNC, 2, "hello"), |
| 15062 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15063 | }; |
| 15064 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15065 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15066 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15067 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15068 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15070 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15071 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15074 | |
| 15075 | // Start the first transaction to set up the SpdySession |
| 15076 | HttpRequestInfo request1; |
| 15077 | request1.method = "GET"; |
| 15078 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15079 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15080 | request1.traffic_annotation = |
| 15081 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15082 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15083 | TestCompletionCallback callback1; |
| 15084 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15085 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15086 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15087 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15088 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15089 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15090 | |
| 15091 | // Now, start the HTTP request |
| 15092 | HttpRequestInfo request2; |
| 15093 | request2.method = "GET"; |
| 15094 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15095 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15096 | request2.traffic_annotation = |
| 15097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15098 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15099 | TestCompletionCallback callback2; |
| 15100 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15101 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15102 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15103 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15104 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15105 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15106 | } |
| 15107 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15108 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15109 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15110 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15111 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15112 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15113 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15114 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15115 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15116 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15118 | |
| 15119 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15120 | // negotiated. |
| 15121 | StaticSocketDataProvider data; |
| 15122 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15123 | |
| 15124 | // 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] | 15125 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15126 | // mocked. This way the request relies on the alternate Job. |
| 15127 | StaticSocketDataProvider data_refused; |
| 15128 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15129 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15130 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15131 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15133 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15134 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15135 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15136 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15137 | http_server_properties->SetHttp2AlternativeService( |
| 15138 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15139 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15140 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15141 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15142 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15143 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15144 | request.traffic_annotation = |
| 15145 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15146 | TestCompletionCallback callback; |
| 15147 | |
| 15148 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15149 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15150 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15151 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15152 | } |
| 15153 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15154 | // 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] | 15155 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15156 | // succeeds, the request should succeed, even if the latter fails because |
| 15157 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15158 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15159 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15160 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15161 | |
| 15162 | // Negotiate HTTP/1.1 with alternative. |
| 15163 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15164 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15166 | |
| 15167 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15168 | // negotiated. |
| 15169 | StaticSocketDataProvider data; |
| 15170 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15171 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15172 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15173 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15174 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15175 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15176 | |
| 15177 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15178 | MockWrite("GET / HTTP/1.1\r\n" |
| 15179 | "Host: www.example.org\r\n" |
| 15180 | "Connection: keep-alive\r\n\r\n"), |
| 15181 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15182 | "Host: www.example.org\r\n" |
| 15183 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15184 | }; |
| 15185 | |
| 15186 | MockRead http_reads[] = { |
| 15187 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15188 | MockRead("Content-Type: text/html\r\n"), |
| 15189 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15190 | MockRead("foobar"), |
| 15191 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15192 | MockRead("Content-Type: text/html\r\n"), |
| 15193 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15194 | MockRead("another"), |
| 15195 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15196 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15197 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15198 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15199 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15201 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15202 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15203 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15204 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15205 | http_server_properties->SetHttp2AlternativeService( |
| 15206 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15207 | |
| 15208 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15209 | HttpRequestInfo request1; |
| 15210 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15211 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15212 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15213 | request1.traffic_annotation = |
| 15214 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15215 | TestCompletionCallback callback1; |
| 15216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15217 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15218 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15219 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15220 | |
| 15221 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15222 | ASSERT_TRUE(response1); |
| 15223 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15224 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15225 | |
| 15226 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15227 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15228 | EXPECT_EQ("foobar", response_data1); |
| 15229 | |
| 15230 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15231 | // for alternative service. |
| 15232 | EXPECT_TRUE( |
| 15233 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15234 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15235 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15236 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15237 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15238 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15239 | HttpRequestInfo request2; |
| 15240 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15241 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15242 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15243 | request2.traffic_annotation = |
| 15244 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15245 | TestCompletionCallback callback2; |
| 15246 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15247 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15248 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15249 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15250 | |
| 15251 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15252 | ASSERT_TRUE(response2); |
| 15253 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15254 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15255 | |
| 15256 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15257 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15258 | EXPECT_EQ("another", response_data2); |
| 15259 | } |
| 15260 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15261 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15262 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15263 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15264 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15265 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15266 | HostPortPair alternative("alternative.example.org", 443); |
| 15267 | std::string origin_url = "https://origin.example.org:443"; |
| 15268 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15269 | |
| 15270 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15271 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15272 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15274 | |
| 15275 | // HTTP/1.1 data for |request1| and |request2|. |
| 15276 | MockWrite http_writes[] = { |
| 15277 | MockWrite( |
| 15278 | "GET / HTTP/1.1\r\n" |
| 15279 | "Host: alternative.example.org\r\n" |
| 15280 | "Connection: keep-alive\r\n\r\n"), |
| 15281 | MockWrite( |
| 15282 | "GET / HTTP/1.1\r\n" |
| 15283 | "Host: alternative.example.org\r\n" |
| 15284 | "Connection: keep-alive\r\n\r\n"), |
| 15285 | }; |
| 15286 | |
| 15287 | MockRead http_reads[] = { |
| 15288 | MockRead( |
| 15289 | "HTTP/1.1 200 OK\r\n" |
| 15290 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15291 | "Content-Length: 40\r\n\r\n" |
| 15292 | "first HTTP/1.1 response from alternative"), |
| 15293 | MockRead( |
| 15294 | "HTTP/1.1 200 OK\r\n" |
| 15295 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15296 | "Content-Length: 41\r\n\r\n" |
| 15297 | "second HTTP/1.1 response from alternative"), |
| 15298 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15299 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15300 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15301 | |
| 15302 | // This test documents that an alternate Job should not pool to an already |
| 15303 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15304 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15305 | StaticSocketDataProvider data_refused; |
| 15306 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15307 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15308 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15309 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15310 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15311 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15312 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15313 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15314 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15315 | http_server_properties->SetHttp2AlternativeService( |
| 15316 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15317 | |
| 15318 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15319 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15320 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15321 | request1.method = "GET"; |
| 15322 | request1.url = GURL(alternative_url); |
| 15323 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15324 | request1.traffic_annotation = |
| 15325 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15326 | TestCompletionCallback callback1; |
| 15327 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15328 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15329 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15330 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15331 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15332 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15333 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15334 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15335 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15336 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15337 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15338 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15339 | |
| 15340 | // Request for origin.example.org, which has an alternative service. This |
| 15341 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15342 | // 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] | 15343 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15344 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15345 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15346 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15347 | request2.method = "GET"; |
| 15348 | request2.url = GURL(origin_url); |
| 15349 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15350 | request2.traffic_annotation = |
| 15351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15352 | TestCompletionCallback callback2; |
| 15353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15354 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15355 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15356 | |
| 15357 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15358 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15359 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15360 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15361 | request3.method = "GET"; |
| 15362 | request3.url = GURL(alternative_url); |
| 15363 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15364 | request3.traffic_annotation = |
| 15365 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15366 | TestCompletionCallback callback3; |
| 15367 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15368 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15369 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15370 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15371 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15372 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15373 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15374 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15375 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15376 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15377 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15378 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15379 | } |
| 15380 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15381 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15382 | const std::string https_url = "https://www.example.org:8080/"; |
| 15383 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15384 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15385 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15386 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15387 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15388 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15389 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15390 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15391 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15392 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15393 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15394 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15395 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15396 | |
| 15397 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15398 | spdy::SpdyHeaderBlock req2_block; |
| 15399 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 15400 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15401 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 15402 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 15403 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15404 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15405 | |
| 15406 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15407 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15408 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15409 | }; |
| 15410 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15411 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15412 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15413 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15414 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15415 | spdy::SpdySerializedFrame body1( |
| 15416 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15417 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15418 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15419 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15420 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15421 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15422 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15423 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15424 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15425 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15426 | CreateMockRead(wrapped_resp1, 4), |
| 15427 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15428 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15429 | CreateMockRead(resp2, 8), |
| 15430 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15431 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15432 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15434 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15435 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15436 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15437 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15438 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15439 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15440 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15441 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15442 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15443 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15444 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15445 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15446 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15447 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15449 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15451 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15452 | |
| 15453 | // Start the first transaction to set up the SpdySession |
| 15454 | HttpRequestInfo request1; |
| 15455 | request1.method = "GET"; |
| 15456 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15457 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15458 | request1.traffic_annotation = |
| 15459 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15460 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15461 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15462 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15463 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15464 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15465 | data1.RunUntilPaused(); |
| 15466 | base::RunLoop().RunUntilIdle(); |
| 15467 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15468 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15469 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15470 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15471 | LoadTimingInfo load_timing_info1; |
| 15472 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15473 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15474 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15475 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15476 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15477 | HttpRequestInfo request2; |
| 15478 | request2.method = "GET"; |
| 15479 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15480 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15481 | request2.traffic_annotation = |
| 15482 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15483 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15484 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15485 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15486 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15487 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15488 | data1.RunUntilPaused(); |
| 15489 | base::RunLoop().RunUntilIdle(); |
| 15490 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15491 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15492 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15493 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15494 | |
| 15495 | LoadTimingInfo load_timing_info2; |
| 15496 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15497 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15498 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15499 | // HTTP requests over a SPDY session should have a different connection |
| 15500 | // socket_log_id than requests over a tunnel. |
| 15501 | 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] | 15502 | } |
| 15503 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15504 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15505 | // that we do not pool other origins that resolve to the same IP when |
| 15506 | // the certificate does not match the new origin. |
| 15507 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15508 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15509 | const std::string url1 = "http://www.example.org/"; |
| 15510 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15511 | const std::string ip_addr = "1.2.3.4"; |
| 15512 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15513 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15514 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15515 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15516 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15517 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15518 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15519 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15520 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15521 | |
| 15522 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15523 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15524 | }; |
| 15525 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15526 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15527 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15528 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15529 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15530 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15531 | }; |
| 15532 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15533 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15534 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15535 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15536 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15537 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15538 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15539 | |
| 15540 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15541 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15542 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15543 | |
| 15544 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15545 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15546 | }; |
| 15547 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15548 | spdy::SpdySerializedFrame resp2( |
| 15549 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15550 | spdy::SpdySerializedFrame body2( |
| 15551 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15552 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15553 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15554 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15555 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15556 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15557 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15558 | |
| 15559 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15560 | // all others direct. |
| 15561 | ProxyConfig proxy_config; |
| 15562 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15563 | session_deps_.proxy_resolution_service = |
| 15564 | std::make_unique<ProxyResolutionService>( |
| 15565 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15566 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15567 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15568 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15569 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15570 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15571 | // Load a valid cert. Note, that this does not need to |
| 15572 | // be valid for proxy because the MockSSLClientSocket does |
| 15573 | // not actually verify it. But SpdySession will use this |
| 15574 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15575 | ssl1.ssl_info.cert = |
| 15576 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15577 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15579 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15580 | |
| 15581 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15582 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15584 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15585 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15586 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15587 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15588 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15589 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15590 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15591 | |
| 15592 | // Start the first transaction to set up the SpdySession |
| 15593 | HttpRequestInfo request1; |
| 15594 | request1.method = "GET"; |
| 15595 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15596 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15597 | request1.traffic_annotation = |
| 15598 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15599 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15600 | TestCompletionCallback callback1; |
| 15601 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15602 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15603 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15604 | data1.RunUntilPaused(); |
| 15605 | base::RunLoop().RunUntilIdle(); |
| 15606 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15607 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15608 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15609 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15610 | |
| 15611 | // Now, start the HTTP request |
| 15612 | HttpRequestInfo request2; |
| 15613 | request2.method = "GET"; |
| 15614 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15615 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15616 | request2.traffic_annotation = |
| 15617 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15618 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15619 | TestCompletionCallback callback2; |
| 15620 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15621 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15622 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15623 | |
| 15624 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15625 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15626 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15627 | } |
| 15628 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15629 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15630 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15631 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15632 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15633 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15634 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15635 | |
| 15636 | MockRead reads1[] = { |
| 15637 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15638 | }; |
| 15639 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15640 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15641 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15642 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15643 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15644 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15645 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15646 | }; |
| 15647 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15648 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15649 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15650 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15651 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15652 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15653 | }; |
| 15654 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15655 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15656 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15657 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15658 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15660 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15661 | |
| 15662 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15663 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15665 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15666 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15667 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15668 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15669 | |
| 15670 | // Start the first transaction to set up the SpdySession and verify that |
| 15671 | // connection was closed. |
| 15672 | HttpRequestInfo request1; |
| 15673 | request1.method = "GET"; |
| 15674 | request1.url = GURL(https_url); |
| 15675 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15676 | request1.traffic_annotation = |
| 15677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15678 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15679 | TestCompletionCallback callback1; |
| 15680 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15681 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15682 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15683 | |
| 15684 | // Now, start the second request and make sure it succeeds. |
| 15685 | HttpRequestInfo request2; |
| 15686 | request2.method = "GET"; |
| 15687 | request2.url = GURL(https_url); |
| 15688 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15689 | request2.traffic_annotation = |
| 15690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15691 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15692 | TestCompletionCallback callback2; |
| 15693 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15694 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15695 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15696 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15697 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15698 | } |
| 15699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15700 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15701 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15702 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15703 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15704 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15705 | |
| 15706 | // Use two different hosts with different IPs so they don't get pooled. |
| 15707 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15708 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15710 | |
| 15711 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15712 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15713 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15714 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15717 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15718 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15719 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15720 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15721 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15722 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15723 | spdy::SpdySerializedFrame host1_resp( |
| 15724 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15725 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15726 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15727 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15728 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15729 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15730 | }; |
| 15731 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15732 | // Use a separate test instance for the separate SpdySession that will be |
| 15733 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15734 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15735 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15736 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15737 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15738 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15739 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15740 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15741 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15742 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 15743 | spdy::SpdySerializedFrame host2_resp( |
| 15744 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15745 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15746 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15747 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15748 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15749 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15750 | }; |
| 15751 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15752 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15753 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15754 | |
| 15755 | MockWrite http_write[] = { |
| 15756 | MockWrite("GET / HTTP/1.1\r\n" |
| 15757 | "Host: www.a.com\r\n" |
| 15758 | "Connection: keep-alive\r\n\r\n"), |
| 15759 | }; |
| 15760 | |
| 15761 | MockRead http_read[] = { |
| 15762 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15763 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15764 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15765 | MockRead("hello!"), |
| 15766 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15767 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15768 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15769 | |
| 15770 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15771 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15772 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15773 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15774 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15775 | |
| 15776 | TestCompletionCallback callback; |
| 15777 | HttpRequestInfo request1; |
| 15778 | request1.method = "GET"; |
| 15779 | request1.url = GURL("https://www.a.com/"); |
| 15780 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15781 | request1.traffic_annotation = |
| 15782 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15783 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15784 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15785 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15786 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15788 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15789 | |
| 15790 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15791 | ASSERT_TRUE(response); |
| 15792 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15793 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15794 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15795 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15796 | |
| 15797 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15798 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15799 | EXPECT_EQ("hello!", response_data); |
| 15800 | trans.reset(); |
| 15801 | EXPECT_TRUE( |
[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 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15805 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15806 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15807 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15808 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15809 | HttpRequestInfo request2; |
| 15810 | request2.method = "GET"; |
| 15811 | request2.url = GURL("https://www.b.com/"); |
| 15812 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15813 | request2.traffic_annotation = |
| 15814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15815 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15816 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15818 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15820 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15821 | |
| 15822 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15823 | ASSERT_TRUE(response); |
| 15824 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15825 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15826 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15827 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15828 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15829 | EXPECT_EQ("hello!", response_data); |
| 15830 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15831 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15832 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15833 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15834 | |
| 15835 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15836 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15837 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15838 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15839 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15840 | HttpRequestInfo request3; |
| 15841 | request3.method = "GET"; |
| 15842 | request3.url = GURL("http://www.a.com/"); |
| 15843 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15844 | request3.traffic_annotation = |
| 15845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15846 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15847 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15849 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15851 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15852 | |
| 15853 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15854 | ASSERT_TRUE(response); |
| 15855 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15856 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15857 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15858 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15859 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15860 | EXPECT_EQ("hello!", response_data); |
| 15861 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15862 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15863 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15864 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15865 | } |
| 15866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15867 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15868 | HttpRequestInfo request; |
| 15869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15870 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15871 | request.traffic_annotation = |
| 15872 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15875 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15876 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15877 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15878 | StaticSocketDataProvider data; |
| 15879 | data.set_connect_data(mock_connect); |
| 15880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15881 | |
| 15882 | TestCompletionCallback callback; |
| 15883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15886 | |
| 15887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15888 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15889 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15890 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15891 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15892 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15893 | |
| 15894 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15895 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15896 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15897 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15898 | |
| 15899 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15900 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15901 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15902 | } |
| 15903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15904 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15905 | HttpRequestInfo request; |
| 15906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15907 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15908 | request.traffic_annotation = |
| 15909 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15910 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15913 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15914 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15915 | StaticSocketDataProvider data; |
| 15916 | data.set_connect_data(mock_connect); |
| 15917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15918 | |
| 15919 | TestCompletionCallback callback; |
| 15920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15921 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15923 | |
| 15924 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15925 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15926 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15927 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15928 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15929 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15930 | |
| 15931 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15932 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15933 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15934 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15935 | |
| 15936 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15937 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15938 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15939 | } |
| 15940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15941 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15942 | HttpRequestInfo request; |
| 15943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15944 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15945 | request.traffic_annotation = |
| 15946 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15947 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15950 | |
| 15951 | MockWrite data_writes[] = { |
| 15952 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15953 | }; |
| 15954 | MockRead data_reads[] = { |
| 15955 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15956 | }; |
| 15957 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15958 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15960 | |
| 15961 | TestCompletionCallback callback; |
| 15962 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15963 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15965 | |
| 15966 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15967 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15968 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15969 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15970 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15971 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15972 | } |
| 15973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15974 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15975 | HttpRequestInfo request; |
| 15976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15977 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15978 | request.traffic_annotation = |
| 15979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15980 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15983 | |
| 15984 | MockWrite data_writes[] = { |
| 15985 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15986 | }; |
| 15987 | MockRead data_reads[] = { |
| 15988 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15989 | }; |
| 15990 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15991 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15992 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15993 | |
| 15994 | TestCompletionCallback callback; |
| 15995 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15996 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15998 | |
| 15999 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16000 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16001 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16002 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16003 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16004 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16005 | } |
| 16006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16007 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16008 | HttpRequestInfo request; |
| 16009 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16010 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16011 | request.traffic_annotation = |
| 16012 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16013 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16014 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16016 | |
| 16017 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16018 | MockWrite( |
| 16019 | "GET / HTTP/1.1\r\n" |
| 16020 | "Host: www.example.org\r\n" |
| 16021 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16022 | }; |
| 16023 | MockRead data_reads[] = { |
| 16024 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16025 | }; |
| 16026 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16027 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16029 | |
| 16030 | TestCompletionCallback callback; |
| 16031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16034 | |
| 16035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16036 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16037 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16038 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16039 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16040 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16041 | } |
| 16042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16043 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16044 | HttpRequestInfo request; |
| 16045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16046 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16047 | request.traffic_annotation = |
| 16048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16049 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16052 | |
| 16053 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16054 | MockWrite( |
| 16055 | "GET / HTTP/1.1\r\n" |
| 16056 | "Host: www.example.org\r\n" |
| 16057 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16058 | }; |
| 16059 | MockRead data_reads[] = { |
| 16060 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16061 | }; |
| 16062 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16063 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16064 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16065 | |
| 16066 | TestCompletionCallback callback; |
| 16067 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16068 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16070 | |
| 16071 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16072 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16073 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16074 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16075 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16076 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16077 | } |
| 16078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16079 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16080 | HttpRequestInfo request; |
| 16081 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16082 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16083 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16084 | request.traffic_annotation = |
| 16085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16089 | |
| 16090 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16091 | MockWrite( |
| 16092 | "GET / HTTP/1.1\r\n" |
| 16093 | "Host: www.example.org\r\n" |
| 16094 | "Connection: keep-alive\r\n" |
| 16095 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16096 | }; |
| 16097 | MockRead data_reads[] = { |
| 16098 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16099 | "Content-Length: 5\r\n\r\n" |
| 16100 | "hello"), |
| 16101 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16102 | }; |
| 16103 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16104 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16106 | |
| 16107 | TestCompletionCallback callback; |
| 16108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16109 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16111 | |
| 16112 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16114 | |
| 16115 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16116 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16117 | std::string foo; |
| 16118 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16119 | EXPECT_EQ("bar", foo); |
| 16120 | } |
| 16121 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16122 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16123 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16124 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16125 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16126 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16127 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16128 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16129 | |
| 16130 | // Set up SSL request. |
| 16131 | |
| 16132 | HttpRequestInfo ssl_request; |
| 16133 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16134 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16135 | ssl_request.traffic_annotation = |
| 16136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16137 | |
| 16138 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16139 | MockWrite( |
| 16140 | "GET / HTTP/1.1\r\n" |
| 16141 | "Host: www.example.org\r\n" |
| 16142 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16143 | }; |
| 16144 | MockRead ssl_reads[] = { |
| 16145 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16146 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16147 | MockRead("hello world"), |
| 16148 | MockRead(SYNCHRONOUS, OK), |
| 16149 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16150 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16151 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16152 | |
| 16153 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16154 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16155 | |
| 16156 | // Set up HTTP request. |
| 16157 | |
| 16158 | HttpRequestInfo http_request; |
| 16159 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16160 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16161 | http_request.traffic_annotation = |
| 16162 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16163 | |
| 16164 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16165 | MockWrite( |
| 16166 | "GET / HTTP/1.1\r\n" |
| 16167 | "Host: www.example.org\r\n" |
| 16168 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16169 | }; |
| 16170 | MockRead http_reads[] = { |
| 16171 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16172 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16173 | MockRead("falafel"), |
| 16174 | MockRead(SYNCHRONOUS, OK), |
| 16175 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16176 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16177 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16178 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16180 | |
| 16181 | // Start the SSL request. |
| 16182 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16183 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16184 | ASSERT_EQ(ERR_IO_PENDING, |
| 16185 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16186 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16187 | |
| 16188 | // Start the HTTP request. Pool should stall. |
| 16189 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16190 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16191 | ASSERT_EQ(ERR_IO_PENDING, |
| 16192 | http_trans.Start(&http_request, http_callback.callback(), |
| 16193 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16194 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16195 | |
| 16196 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16197 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16198 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16199 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16200 | EXPECT_EQ("hello world", response_data); |
| 16201 | |
| 16202 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16203 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16204 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16205 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16206 | |
| 16207 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16208 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16209 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16210 | EXPECT_EQ("falafel", response_data); |
| 16211 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16212 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16213 | } |
| 16214 | |
| 16215 | // Tests that when a SSL connection is established but there's no corresponding |
| 16216 | // request that needs it, the new socket is closed if the transport socket pool |
| 16217 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16218 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16219 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16220 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16221 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16222 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16223 | |
| 16224 | // Set up an ssl request. |
| 16225 | |
| 16226 | HttpRequestInfo ssl_request; |
| 16227 | ssl_request.method = "GET"; |
| 16228 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16229 | ssl_request.traffic_annotation = |
| 16230 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16231 | |
| 16232 | // No data will be sent on the SSL socket. |
| 16233 | StaticSocketDataProvider ssl_data; |
| 16234 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16235 | |
| 16236 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16237 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16238 | |
| 16239 | // Set up HTTP request. |
| 16240 | |
| 16241 | HttpRequestInfo http_request; |
| 16242 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16243 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16244 | http_request.traffic_annotation = |
| 16245 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16246 | |
| 16247 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16248 | MockWrite( |
| 16249 | "GET / HTTP/1.1\r\n" |
| 16250 | "Host: www.example.org\r\n" |
| 16251 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16252 | }; |
| 16253 | MockRead http_reads[] = { |
| 16254 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16255 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16256 | MockRead("falafel"), |
| 16257 | MockRead(SYNCHRONOUS, OK), |
| 16258 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16259 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16260 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16261 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16263 | |
| 16264 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16265 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16266 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16267 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16268 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16269 | |
| 16270 | // Start the HTTP request. Pool should stall. |
| 16271 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16272 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16273 | ASSERT_EQ(ERR_IO_PENDING, |
| 16274 | http_trans.Start(&http_request, http_callback.callback(), |
| 16275 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16276 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16277 | |
| 16278 | // The SSL connection will automatically be closed once the connection is |
| 16279 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16280 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16282 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16283 | EXPECT_EQ("falafel", response_data); |
| 16284 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16285 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16286 | } |
| 16287 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16288 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16289 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16290 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16291 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16292 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16293 | |
| 16294 | HttpRequestInfo request; |
| 16295 | request.method = "POST"; |
| 16296 | request.url = GURL("http://www.foo.com/"); |
| 16297 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16298 | request.traffic_annotation = |
| 16299 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16303 | // Send headers successfully, but get an error while sending the body. |
| 16304 | MockWrite data_writes[] = { |
| 16305 | MockWrite("POST / HTTP/1.1\r\n" |
| 16306 | "Host: www.foo.com\r\n" |
| 16307 | "Connection: keep-alive\r\n" |
| 16308 | "Content-Length: 3\r\n\r\n"), |
| 16309 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16310 | }; |
| 16311 | |
| 16312 | MockRead data_reads[] = { |
| 16313 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16314 | MockRead("hello world"), |
| 16315 | MockRead(SYNCHRONOUS, OK), |
| 16316 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16317 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16319 | |
| 16320 | TestCompletionCallback callback; |
| 16321 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16322 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16324 | |
| 16325 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16328 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16329 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16330 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16331 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16332 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16333 | |
| 16334 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16335 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16337 | EXPECT_EQ("hello world", response_data); |
| 16338 | } |
| 16339 | |
| 16340 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16341 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16342 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16343 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16345 | MockWrite data_writes[] = { |
| 16346 | MockWrite("GET / HTTP/1.1\r\n" |
| 16347 | "Host: www.foo.com\r\n" |
| 16348 | "Connection: keep-alive\r\n\r\n"), |
| 16349 | MockWrite("POST / HTTP/1.1\r\n" |
| 16350 | "Host: www.foo.com\r\n" |
| 16351 | "Connection: keep-alive\r\n" |
| 16352 | "Content-Length: 3\r\n\r\n"), |
| 16353 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16354 | }; |
| 16355 | |
| 16356 | MockRead data_reads[] = { |
| 16357 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16358 | "Content-Length: 14\r\n\r\n"), |
| 16359 | MockRead("first response"), |
| 16360 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16361 | "Content-Length: 15\r\n\r\n"), |
| 16362 | MockRead("second response"), |
| 16363 | MockRead(SYNCHRONOUS, OK), |
| 16364 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16365 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16367 | |
| 16368 | TestCompletionCallback callback; |
| 16369 | HttpRequestInfo request1; |
| 16370 | request1.method = "GET"; |
| 16371 | request1.url = GURL("http://www.foo.com/"); |
| 16372 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16373 | request1.traffic_annotation = |
| 16374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16375 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16376 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16377 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16378 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16380 | |
| 16381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16383 | |
| 16384 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16385 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16386 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16387 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16388 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16389 | |
| 16390 | std::string response_data1; |
| 16391 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16393 | EXPECT_EQ("first response", response_data1); |
| 16394 | // Delete the transaction to release the socket back into the socket pool. |
| 16395 | trans1.reset(); |
| 16396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16397 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16398 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16399 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16400 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16401 | |
| 16402 | HttpRequestInfo request2; |
| 16403 | request2.method = "POST"; |
| 16404 | request2.url = GURL("http://www.foo.com/"); |
| 16405 | request2.upload_data_stream = &upload_data_stream; |
| 16406 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16407 | request2.traffic_annotation = |
| 16408 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16410 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16411 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16413 | |
| 16414 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16417 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16418 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16419 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16420 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16421 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16422 | |
| 16423 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16424 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16425 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16426 | EXPECT_EQ("second response", response_data2); |
| 16427 | } |
| 16428 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16429 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16430 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16431 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16432 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16433 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16434 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16435 | |
| 16436 | HttpRequestInfo request; |
| 16437 | request.method = "POST"; |
| 16438 | request.url = GURL("http://www.foo.com/"); |
| 16439 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16440 | request.traffic_annotation = |
| 16441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16445 | // Send headers successfully, but get an error while sending the body. |
| 16446 | MockWrite data_writes[] = { |
| 16447 | MockWrite("POST / HTTP/1.1\r\n" |
| 16448 | "Host: www.foo.com\r\n" |
| 16449 | "Connection: keep-alive\r\n" |
| 16450 | "Content-Length: 3\r\n\r\n" |
| 16451 | "fo"), |
| 16452 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16453 | }; |
| 16454 | |
| 16455 | MockRead data_reads[] = { |
| 16456 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16457 | MockRead("hello world"), |
| 16458 | MockRead(SYNCHRONOUS, OK), |
| 16459 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16460 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16462 | |
| 16463 | TestCompletionCallback callback; |
| 16464 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16465 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16467 | |
| 16468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16471 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16472 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16473 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16474 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16475 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16476 | |
| 16477 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16478 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16479 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16480 | EXPECT_EQ("hello world", response_data); |
| 16481 | } |
| 16482 | |
| 16483 | // This tests the more common case than the previous test, where headers and |
| 16484 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16485 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16486 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16487 | |
| 16488 | HttpRequestInfo request; |
| 16489 | request.method = "POST"; |
| 16490 | request.url = GURL("http://www.foo.com/"); |
| 16491 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16492 | request.traffic_annotation = |
| 16493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16494 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16497 | // Send headers successfully, but get an error while sending the body. |
| 16498 | MockWrite data_writes[] = { |
| 16499 | MockWrite("POST / HTTP/1.1\r\n" |
| 16500 | "Host: www.foo.com\r\n" |
| 16501 | "Connection: keep-alive\r\n" |
| 16502 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16503 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16504 | }; |
| 16505 | |
| 16506 | MockRead data_reads[] = { |
| 16507 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16508 | MockRead("hello world"), |
| 16509 | MockRead(SYNCHRONOUS, OK), |
| 16510 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16511 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16513 | |
| 16514 | TestCompletionCallback callback; |
| 16515 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16516 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16518 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16519 | // they can't be merged with the body in a single send. Not currently |
| 16520 | // necessary since a chunked body is never merged with headers, but this makes |
| 16521 | // the test more future proof. |
| 16522 | base::RunLoop().RunUntilIdle(); |
| 16523 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16524 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16525 | |
| 16526 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16527 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16529 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16530 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16531 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16532 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16533 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16534 | |
| 16535 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16536 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16537 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16538 | EXPECT_EQ("hello world", response_data); |
| 16539 | } |
| 16540 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16541 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16542 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16543 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16544 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16545 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16546 | |
| 16547 | HttpRequestInfo request; |
| 16548 | request.method = "POST"; |
| 16549 | request.url = GURL("http://www.foo.com/"); |
| 16550 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16551 | request.traffic_annotation = |
| 16552 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16553 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16556 | |
| 16557 | MockWrite data_writes[] = { |
| 16558 | MockWrite("POST / HTTP/1.1\r\n" |
| 16559 | "Host: www.foo.com\r\n" |
| 16560 | "Connection: keep-alive\r\n" |
| 16561 | "Content-Length: 3\r\n\r\n"), |
| 16562 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16563 | }; |
| 16564 | |
| 16565 | MockRead data_reads[] = { |
| 16566 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16567 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16568 | MockRead("hello world"), |
| 16569 | MockRead(SYNCHRONOUS, OK), |
| 16570 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16571 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16572 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16573 | |
| 16574 | TestCompletionCallback callback; |
| 16575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16576 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16578 | |
| 16579 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16583 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16584 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16585 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16586 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16587 | |
| 16588 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16589 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16590 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16591 | EXPECT_EQ("hello world", response_data); |
| 16592 | } |
| 16593 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16594 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16595 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16596 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16597 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16598 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16599 | |
| 16600 | HttpRequestInfo request; |
| 16601 | request.method = "POST"; |
| 16602 | request.url = GURL("http://www.foo.com/"); |
| 16603 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16604 | request.traffic_annotation = |
| 16605 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16608 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16609 | // Send headers successfully, but get an error while sending the body. |
| 16610 | MockWrite data_writes[] = { |
| 16611 | MockWrite("POST / HTTP/1.1\r\n" |
| 16612 | "Host: www.foo.com\r\n" |
| 16613 | "Connection: keep-alive\r\n" |
| 16614 | "Content-Length: 3\r\n\r\n"), |
| 16615 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16616 | }; |
| 16617 | |
| 16618 | MockRead data_reads[] = { |
| 16619 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16620 | MockRead("hello world"), |
| 16621 | MockRead(SYNCHRONOUS, OK), |
| 16622 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16623 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16625 | |
| 16626 | TestCompletionCallback callback; |
| 16627 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16628 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16630 | |
| 16631 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16632 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16633 | } |
| 16634 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16635 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16636 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16637 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16638 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16639 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16640 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16641 | |
| 16642 | HttpRequestInfo request; |
| 16643 | request.method = "POST"; |
| 16644 | request.url = GURL("http://www.foo.com/"); |
| 16645 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16646 | request.traffic_annotation = |
| 16647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16649 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16651 | // Send headers successfully, but get an error while sending the body. |
| 16652 | MockWrite data_writes[] = { |
| 16653 | MockWrite("POST / HTTP/1.1\r\n" |
| 16654 | "Host: www.foo.com\r\n" |
| 16655 | "Connection: keep-alive\r\n" |
| 16656 | "Content-Length: 3\r\n\r\n"), |
| 16657 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16658 | }; |
| 16659 | |
| 16660 | MockRead data_reads[] = { |
| 16661 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16662 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16663 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16664 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16665 | MockRead(SYNCHRONOUS, OK), |
| 16666 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16667 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16668 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16669 | |
| 16670 | TestCompletionCallback callback; |
| 16671 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16672 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16674 | |
| 16675 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16676 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16677 | } |
| 16678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16679 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16680 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16681 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16682 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16683 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16684 | |
| 16685 | HttpRequestInfo request; |
| 16686 | request.method = "POST"; |
| 16687 | request.url = GURL("http://www.foo.com/"); |
| 16688 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16689 | request.traffic_annotation = |
| 16690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16694 | // Send headers successfully, but get an error while sending the body. |
| 16695 | MockWrite data_writes[] = { |
| 16696 | MockWrite("POST / HTTP/1.1\r\n" |
| 16697 | "Host: www.foo.com\r\n" |
| 16698 | "Connection: keep-alive\r\n" |
| 16699 | "Content-Length: 3\r\n\r\n"), |
| 16700 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16701 | }; |
| 16702 | |
| 16703 | MockRead data_reads[] = { |
| 16704 | MockRead("HTTP 0.9 rocks!"), |
| 16705 | MockRead(SYNCHRONOUS, OK), |
| 16706 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16707 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16709 | |
| 16710 | TestCompletionCallback callback; |
| 16711 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16712 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16714 | |
| 16715 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16716 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16717 | } |
| 16718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16719 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16720 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16721 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16722 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16723 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16724 | |
| 16725 | HttpRequestInfo request; |
| 16726 | request.method = "POST"; |
| 16727 | request.url = GURL("http://www.foo.com/"); |
| 16728 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16729 | request.traffic_annotation = |
| 16730 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16734 | // Send headers successfully, but get an error while sending the body. |
| 16735 | MockWrite data_writes[] = { |
| 16736 | MockWrite("POST / HTTP/1.1\r\n" |
| 16737 | "Host: www.foo.com\r\n" |
| 16738 | "Connection: keep-alive\r\n" |
| 16739 | "Content-Length: 3\r\n\r\n"), |
| 16740 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16741 | }; |
| 16742 | |
| 16743 | MockRead data_reads[] = { |
| 16744 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16745 | MockRead(SYNCHRONOUS, OK), |
| 16746 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16747 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16749 | |
| 16750 | TestCompletionCallback callback; |
| 16751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16754 | |
| 16755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16756 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16757 | } |
| 16758 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16759 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 16760 | |
| 16761 | namespace { |
| 16762 | |
| 16763 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 16764 | headers->SetHeader("Connection", "Upgrade"); |
| 16765 | headers->SetHeader("Upgrade", "websocket"); |
| 16766 | headers->SetHeader("Origin", "http://www.example.org"); |
| 16767 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16768 | } |
| 16769 | |
| 16770 | } // namespace |
| 16771 | |
| 16772 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16773 | for (bool secure : {true, false}) { |
| 16774 | MockWrite data_writes[] = { |
| 16775 | MockWrite("GET / HTTP/1.1\r\n" |
| 16776 | "Host: www.example.org\r\n" |
| 16777 | "Connection: Upgrade\r\n" |
| 16778 | "Upgrade: websocket\r\n" |
| 16779 | "Origin: http://www.example.org\r\n" |
| 16780 | "Sec-WebSocket-Version: 13\r\n" |
| 16781 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16782 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16783 | "client_max_window_bits\r\n\r\n")}; |
| 16784 | |
| 16785 | MockRead data_reads[] = { |
| 16786 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16787 | "Upgrade: websocket\r\n" |
| 16788 | "Connection: Upgrade\r\n" |
| 16789 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 16790 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16791 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16792 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16793 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16794 | if (secure) |
| 16795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16796 | |
| 16797 | HttpRequestInfo request; |
| 16798 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16799 | request.url = |
| 16800 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 16801 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16802 | request.traffic_annotation = |
| 16803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16804 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16805 | TestWebSocketHandshakeStreamCreateHelper |
| 16806 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16807 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16809 | HttpNetworkTransaction trans(LOW, session.get()); |
| 16810 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16811 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16812 | |
| 16813 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16816 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16817 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 16818 | ASSERT_TRUE(stream_request); |
| 16819 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 16820 | stream_request->websocket_handshake_stream_create_helper()); |
| 16821 | |
| 16822 | rv = callback.WaitForResult(); |
| 16823 | EXPECT_THAT(rv, IsOk()); |
| 16824 | |
| 16825 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 16826 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16827 | } |
| 16828 | } |
| 16829 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16830 | // Verify that proxy headers are not sent to the destination server when |
| 16831 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16832 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16833 | HttpRequestInfo request; |
| 16834 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16835 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16836 | request.traffic_annotation = |
| 16837 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16838 | AddWebSocketHeaders(&request.extra_headers); |
| 16839 | |
| 16840 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16841 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16842 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16843 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16846 | |
| 16847 | // Since a proxy is configured, try to establish a tunnel. |
| 16848 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16849 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16850 | "Host: www.example.org:443\r\n" |
| 16851 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16852 | |
| 16853 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16854 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16855 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16856 | "Host: www.example.org:443\r\n" |
| 16857 | "Proxy-Connection: keep-alive\r\n" |
| 16858 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16859 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16860 | MockWrite("GET / HTTP/1.1\r\n" |
| 16861 | "Host: www.example.org\r\n" |
| 16862 | "Connection: Upgrade\r\n" |
| 16863 | "Upgrade: websocket\r\n" |
| 16864 | "Origin: http://www.example.org\r\n" |
| 16865 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16866 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16867 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16868 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16869 | |
| 16870 | // The proxy responds to the connect with a 407, using a persistent |
| 16871 | // connection. |
| 16872 | MockRead data_reads[] = { |
| 16873 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16874 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 16875 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 16876 | "Content-Length: 0\r\n" |
| 16877 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16878 | |
| 16879 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16880 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16881 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16882 | "Upgrade: websocket\r\n" |
| 16883 | "Connection: Upgrade\r\n" |
| 16884 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16885 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16886 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16887 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16888 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16890 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16891 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 16892 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16893 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16894 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16895 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16896 | &websocket_stream_create_helper); |
| 16897 | |
| 16898 | { |
| 16899 | TestCompletionCallback callback; |
| 16900 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16901 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16903 | |
| 16904 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16905 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16906 | } |
| 16907 | |
| 16908 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16909 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16910 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16911 | EXPECT_EQ(407, response->headers->response_code()); |
| 16912 | |
| 16913 | { |
| 16914 | TestCompletionCallback callback; |
| 16915 | |
| 16916 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16917 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16919 | |
| 16920 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16921 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16922 | } |
| 16923 | |
| 16924 | response = trans->GetResponseInfo(); |
| 16925 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16926 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16927 | |
| 16928 | EXPECT_EQ(101, response->headers->response_code()); |
| 16929 | |
| 16930 | trans.reset(); |
| 16931 | session->CloseAllConnections(); |
| 16932 | } |
| 16933 | |
| 16934 | // Verify that proxy headers are not sent to the destination server when |
| 16935 | // establishing a tunnel for an insecure WebSocket connection. |
| 16936 | // This requires the authentication info to be injected into the auth cache |
| 16937 | // due to crbug.com/395064 |
| 16938 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16939 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16940 | HttpRequestInfo request; |
| 16941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16942 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16943 | request.traffic_annotation = |
| 16944 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16945 | AddWebSocketHeaders(&request.extra_headers); |
| 16946 | |
| 16947 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16948 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16949 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16950 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16951 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16953 | |
| 16954 | MockWrite data_writes[] = { |
| 16955 | // Try to establish a tunnel for the WebSocket connection, with |
| 16956 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16957 | // they cannot and will not use the same TCP/IP connection as the |
| 16958 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16959 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16960 | "Host: www.example.org:80\r\n" |
| 16961 | "Proxy-Connection: keep-alive\r\n" |
| 16962 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16963 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16964 | MockWrite("GET / HTTP/1.1\r\n" |
| 16965 | "Host: www.example.org\r\n" |
| 16966 | "Connection: Upgrade\r\n" |
| 16967 | "Upgrade: websocket\r\n" |
| 16968 | "Origin: http://www.example.org\r\n" |
| 16969 | "Sec-WebSocket-Version: 13\r\n" |
| 16970 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16971 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16972 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16973 | |
| 16974 | MockRead data_reads[] = { |
| 16975 | // HTTP CONNECT with credentials. |
| 16976 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16977 | |
| 16978 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16979 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16980 | "Upgrade: websocket\r\n" |
| 16981 | "Connection: Upgrade\r\n" |
| 16982 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16983 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16984 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16986 | |
| 16987 | session->http_auth_cache()->Add( |
| 16988 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16989 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16990 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16991 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 16992 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16993 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16994 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16995 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16996 | &websocket_stream_create_helper); |
| 16997 | |
| 16998 | TestCompletionCallback callback; |
| 16999 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17000 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17002 | |
| 17003 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17004 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17005 | |
| 17006 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17007 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17008 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17009 | |
| 17010 | EXPECT_EQ(101, response->headers->response_code()); |
| 17011 | |
| 17012 | trans.reset(); |
| 17013 | session->CloseAllConnections(); |
| 17014 | } |
| 17015 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17016 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17018 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17019 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17020 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17021 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17022 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17023 | |
| 17024 | HttpRequestInfo request; |
| 17025 | request.method = "POST"; |
| 17026 | request.url = GURL("http://www.foo.com/"); |
| 17027 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17028 | request.traffic_annotation = |
| 17029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17033 | MockWrite data_writes[] = { |
| 17034 | MockWrite("POST / HTTP/1.1\r\n" |
| 17035 | "Host: www.foo.com\r\n" |
| 17036 | "Connection: keep-alive\r\n" |
| 17037 | "Content-Length: 3\r\n\r\n"), |
| 17038 | MockWrite("foo"), |
| 17039 | }; |
| 17040 | |
| 17041 | MockRead data_reads[] = { |
| 17042 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17043 | MockRead(SYNCHRONOUS, OK), |
| 17044 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17045 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17046 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17047 | |
| 17048 | TestCompletionCallback callback; |
| 17049 | |
| 17050 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17051 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17052 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17053 | |
| 17054 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17055 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17056 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17057 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17058 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17059 | } |
| 17060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17061 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17062 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17063 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17064 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17065 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17066 | |
| 17067 | HttpRequestInfo request; |
| 17068 | request.method = "POST"; |
| 17069 | request.url = GURL("http://www.foo.com/"); |
| 17070 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17071 | request.traffic_annotation = |
| 17072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17076 | MockWrite data_writes[] = { |
| 17077 | MockWrite("POST / HTTP/1.1\r\n" |
| 17078 | "Host: www.foo.com\r\n" |
| 17079 | "Connection: keep-alive\r\n" |
| 17080 | "Content-Length: 3\r\n\r\n"), |
| 17081 | MockWrite("foo"), |
| 17082 | }; |
| 17083 | |
| 17084 | MockRead data_reads[] = { |
| 17085 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17086 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17087 | MockRead(SYNCHRONOUS, OK), |
| 17088 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17089 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17090 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17091 | |
| 17092 | TestCompletionCallback callback; |
| 17093 | |
| 17094 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17095 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17096 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17097 | |
| 17098 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17099 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17100 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17101 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17102 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17103 | } |
| 17104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17105 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17106 | ChunkedUploadDataStream upload_data_stream(0); |
| 17107 | |
| 17108 | HttpRequestInfo request; |
| 17109 | request.method = "POST"; |
| 17110 | request.url = GURL("http://www.foo.com/"); |
| 17111 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17112 | request.traffic_annotation = |
| 17113 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17114 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17117 | // Send headers successfully, but get an error while sending the body. |
| 17118 | MockWrite data_writes[] = { |
| 17119 | MockWrite("POST / HTTP/1.1\r\n" |
| 17120 | "Host: www.foo.com\r\n" |
| 17121 | "Connection: keep-alive\r\n" |
| 17122 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17123 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17124 | }; |
| 17125 | |
| 17126 | MockRead data_reads[] = { |
| 17127 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17128 | MockRead(SYNCHRONOUS, OK), |
| 17129 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17130 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17132 | |
| 17133 | TestCompletionCallback callback; |
| 17134 | |
| 17135 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17136 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17137 | |
| 17138 | base::RunLoop().RunUntilIdle(); |
| 17139 | upload_data_stream.AppendData("f", 1, false); |
| 17140 | |
| 17141 | base::RunLoop().RunUntilIdle(); |
| 17142 | upload_data_stream.AppendData("oo", 2, true); |
| 17143 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17144 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17145 | |
| 17146 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17147 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17148 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17149 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17150 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17151 | } |
| 17152 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17153 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17154 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17155 | const std::string https_url = "https://www.example.com"; |
| 17156 | HttpRequestInfo request; |
| 17157 | request.url = GURL(https_url); |
| 17158 | request.method = "GET"; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17159 | request.traffic_annotation = |
| 17160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17161 | |
| 17162 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17163 | ssl.ssl_info.token_binding_negotiated = true; |
| 17164 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17165 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17166 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17167 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame^] | 17168 | spdy::SpdySerializedFrame resp( |
| 17169 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 17170 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17171 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17172 | MockRead(ASYNC, ERR_IO_PENDING)}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17173 | StaticSocketDataProvider data(reads, base::span<MockWrite>()); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17175 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17176 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17177 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17178 | |
| 17179 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17180 | TestCompletionCallback callback; |
| 17181 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17182 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17183 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 17184 | RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17185 | |
| 17186 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17187 | HttpRequestHeaders headers; |
| 17188 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17189 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17190 | } |
| 17191 | #endif // !defined(OS_IOS) |
| 17192 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17193 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17194 | const std::string& accept_encoding, |
| 17195 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17196 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17197 | bool should_match) { |
| 17198 | HttpRequestInfo request; |
| 17199 | request.method = "GET"; |
| 17200 | request.url = GURL("http://www.foo.com/"); |
| 17201 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17202 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17203 | request.traffic_annotation = |
| 17204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17205 | |
| 17206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17208 | // Send headers successfully, but get an error while sending the body. |
| 17209 | MockWrite data_writes[] = { |
| 17210 | MockWrite("GET / HTTP/1.1\r\n" |
| 17211 | "Host: www.foo.com\r\n" |
| 17212 | "Connection: keep-alive\r\n" |
| 17213 | "Accept-Encoding: "), |
| 17214 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17215 | }; |
| 17216 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17217 | std::string response_code = "200 OK"; |
| 17218 | std::string extra; |
| 17219 | if (!location.empty()) { |
| 17220 | response_code = "301 Redirect\r\nLocation: "; |
| 17221 | response_code.append(location); |
| 17222 | } |
| 17223 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17224 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17225 | MockRead("HTTP/1.0 "), |
| 17226 | MockRead(response_code.data()), |
| 17227 | MockRead("\r\nContent-Encoding: "), |
| 17228 | MockRead(content_encoding.data()), |
| 17229 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17230 | MockRead(SYNCHRONOUS, OK), |
| 17231 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17232 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17233 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17234 | |
| 17235 | TestCompletionCallback callback; |
| 17236 | |
| 17237 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17239 | |
| 17240 | rv = callback.WaitForResult(); |
| 17241 | if (should_match) { |
| 17242 | EXPECT_THAT(rv, IsOk()); |
| 17243 | } else { |
| 17244 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17245 | } |
| 17246 | } |
| 17247 | |
| 17248 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17249 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17250 | } |
| 17251 | |
| 17252 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17253 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17254 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17255 | } |
| 17256 | |
| 17257 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17258 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17259 | "", false); |
| 17260 | } |
| 17261 | |
| 17262 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17263 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17264 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17265 | } |
| 17266 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17267 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17268 | ProxyConfig proxy_config; |
| 17269 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17270 | proxy_config.set_pac_mandatory(true); |
| 17271 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17272 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17273 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17274 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17275 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17276 | |
| 17277 | HttpRequestInfo request; |
| 17278 | request.method = "GET"; |
| 17279 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17280 | request.traffic_annotation = |
| 17281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17282 | |
| 17283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17285 | |
| 17286 | TestCompletionCallback callback; |
| 17287 | |
| 17288 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17290 | EXPECT_THAT(callback.WaitForResult(), |
| 17291 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17292 | } |
| 17293 | |
| 17294 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17295 | ProxyConfig proxy_config; |
| 17296 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17297 | proxy_config.set_pac_mandatory(true); |
| 17298 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17299 | new MockAsyncProxyResolverFactory(false); |
| 17300 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17301 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17302 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17303 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17304 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17305 | HttpRequestInfo request; |
| 17306 | request.method = "GET"; |
| 17307 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17308 | request.traffic_annotation = |
| 17309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17310 | |
| 17311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17312 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17313 | |
| 17314 | TestCompletionCallback callback; |
| 17315 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17317 | |
| 17318 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17319 | ERR_FAILED, &resolver); |
| 17320 | EXPECT_THAT(callback.WaitForResult(), |
| 17321 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17322 | } |
| 17323 | |
| 17324 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17325 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17326 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17327 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17328 | session_deps_.enable_quic = false; |
| 17329 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17330 | |
| 17331 | HttpRequestInfo request; |
| 17332 | request.method = "GET"; |
| 17333 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17334 | request.traffic_annotation = |
| 17335 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17336 | |
| 17337 | TestCompletionCallback callback; |
| 17338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17339 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17341 | |
| 17342 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17343 | } |
| 17344 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17345 | } // namespace net |