[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" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 33 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 38 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 39 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 45 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 46 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 47 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 48 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 49 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 53 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 56 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 57 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 58 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 59 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 61 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 62 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 63 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 64 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 65 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 66 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 67 | #include "net/log/test_net_log_entry.h" |
| 68 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 69 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 70 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 71 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 72 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 73 | #include "net/proxy_resolution/proxy_resolver.h" |
| 74 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 75 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 76 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 78 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 79 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 80 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 81 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 82 | #include "net/socket/socket_test_util.h" |
| 83 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 84 | #include "net/spdy/spdy_session.h" |
| 85 | #include "net/spdy/spdy_session_pool.h" |
| 86 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 87 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 88 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 89 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 90 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 91 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 92 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 93 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 94 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 95 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 2e003eea | 2018-05-02 00:24:29 | [diff] [blame] | 96 | #include "net/third_party/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 97 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 98 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 99 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 100 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 101 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 102 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 103 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 105 | #if defined(NTLM_PORTABLE) |
| 106 | #include "base/base64.h" |
| 107 | #include "net/ntlm/ntlm_test_data.h" |
| 108 | #endif |
| 109 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 110 | using net::test::IsError; |
| 111 | using net::test::IsOk; |
| 112 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 113 | using base::ASCIIToUTF16; |
| 114 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 115 | //----------------------------------------------------------------------------- |
| 116 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 117 | namespace net { |
| 118 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 119 | namespace { |
| 120 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 121 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 122 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 123 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 124 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 125 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 126 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 127 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 128 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 129 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 130 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 131 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 132 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 133 | const char kAlternativeServiceHttpHeader[] = |
| 134 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 135 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 136 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 137 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 138 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 139 | } |
| 140 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 141 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 142 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 143 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 144 | } |
| 145 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 146 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 147 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 148 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 149 | } |
| 150 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 151 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 152 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 153 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 154 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 155 | if (!params) |
| 156 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 157 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 158 | if (!params->GetList("headers", &header_list)) |
| 159 | return false; |
| 160 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 161 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 162 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 163 | return true; |
| 164 | } |
| 165 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 166 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 167 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 168 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 169 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 170 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 171 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 172 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 173 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 174 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 175 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 176 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 177 | |
| 178 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 179 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 180 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 181 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 182 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 183 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 184 | } |
| 185 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 187 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 189 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 190 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 191 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | |
| 193 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 194 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 195 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 196 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 197 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 198 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 199 | load_timing_info.send_start); |
| 200 | |
| 201 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 202 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 203 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 204 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 205 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 206 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 210 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 211 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 213 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 215 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | |
| 217 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 218 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 219 | load_timing_info.proxy_resolve_end); |
| 220 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 221 | load_timing_info.send_start); |
| 222 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 224 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 226 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 227 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 231 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 232 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 233 | int connect_timing_flags) { |
| 234 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 235 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
| 237 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 238 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 239 | load_timing_info.proxy_resolve_end); |
| 240 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 241 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 242 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 243 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 245 | load_timing_info.send_start); |
| 246 | |
| 247 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 248 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 249 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 250 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 251 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 252 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 253 | } |
| 254 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 255 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 256 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 257 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 258 | } |
| 259 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 260 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 261 | public: |
| 262 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 263 | |
| 264 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 265 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 266 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 267 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 268 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 269 | return ERR_PAC_SCRIPT_FAILED; |
| 270 | } |
| 271 | }; |
| 272 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 273 | class TestSSLConfigService : public SSLConfigService { |
| 274 | public: |
| 275 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 276 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 277 | |
| 278 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 279 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 280 | bool CanShareConnectionWithClientCerts( |
| 281 | const std::string& hostname) const override { |
| 282 | return false; |
| 283 | } |
| 284 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 285 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 286 | SSLConfig config_; |
| 287 | }; |
| 288 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 289 | } // namespace |
| 290 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 291 | class HttpNetworkTransactionTest : public PlatformTest, |
| 292 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 293 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 294 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 295 | // Important to restore the per-pool limit first, since the pool limit must |
| 296 | // always be greater than group limit, and the tests reduce both limits. |
| 297 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 298 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 299 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 300 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 301 | } |
| 302 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 303 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 304 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 305 | : ssl_(ASYNC, OK), |
| 306 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 307 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 308 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 309 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 310 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 311 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 312 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 313 | struct SimpleGetHelperResult { |
| 314 | int rv; |
| 315 | std::string status_line; |
| 316 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 317 | int64_t total_received_bytes; |
| 318 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 319 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 320 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 321 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 322 | }; |
| 323 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 324 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 325 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 326 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 327 | } |
| 328 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 329 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 330 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 331 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 332 | // Empty the current queue. |
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 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 335 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 336 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 337 | } |
| 338 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 339 | // Either |write_failure| specifies a write failure or |read_failure| |
| 340 | // specifies a read failure when using a reused socket. In either case, the |
| 341 | // failure should cause the network transaction to resend the request, and the |
| 342 | // other argument should be NULL. |
| 343 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 344 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 345 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 346 | // Either |write_failure| specifies a write failure or |read_failure| |
| 347 | // specifies a read failure when using a reused socket. In either case, the |
| 348 | // failure should cause the network transaction to resend the request, and the |
| 349 | // other argument should be NULL. |
| 350 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 351 | const MockRead* read_failure, |
| 352 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 353 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 354 | SimpleGetHelperResult SimpleGetHelperForData( |
| 355 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 356 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 357 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 358 | HttpRequestInfo request; |
| 359 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 360 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 361 | request.traffic_annotation = |
| 362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 363 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 364 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 365 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 366 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 367 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 368 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 369 | for (auto* provider : providers) { |
| 370 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 371 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 373 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 374 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 375 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 376 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 378 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 379 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 380 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 381 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 382 | |
| 383 | // Even in the failure cases that use this function, connections are always |
| 384 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 385 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 386 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 387 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 388 | if (out.rv != OK) |
| 389 | return out; |
| 390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 392 | // Can't use ASSERT_* inside helper functions like this, so |
| 393 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 394 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 395 | out.rv = ERR_UNEXPECTED; |
| 396 | return out; |
| 397 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 398 | out.status_line = response->headers->GetStatusLine(); |
| 399 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 400 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 401 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 402 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 403 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 404 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 405 | EXPECT_EQ(got_endpoint, |
| 406 | out.remote_endpoint_after_start.address().size() > 0); |
| 407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 408 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 409 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 410 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 411 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 412 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 413 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 414 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 415 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 416 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 417 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 418 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 419 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 420 | std::string line; |
| 421 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 422 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 423 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 424 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 425 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 426 | std::string value; |
| 427 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 428 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 429 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 430 | EXPECT_EQ("keep-alive", value); |
| 431 | |
| 432 | std::string response_headers; |
| 433 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 434 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 435 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 437 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 438 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 439 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 441 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 442 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 443 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 444 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 445 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 446 | MockWrite data_writes[] = { |
| 447 | MockWrite("GET / HTTP/1.1\r\n" |
| 448 | "Host: www.example.org\r\n" |
| 449 | "Connection: keep-alive\r\n\r\n"), |
| 450 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 451 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 452 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 453 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 454 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 455 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 456 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 457 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 458 | } |
| 459 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 460 | void AddSSLSocketData() { |
| 461 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 462 | ssl_.ssl_info.cert = |
| 463 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 464 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 465 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 466 | } |
| 467 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 468 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 469 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 472 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 473 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 474 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 475 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 476 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 477 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 478 | |
| 479 | // Original socket limits. Some tests set these. Safest to always restore |
| 480 | // them once each test has been run. |
| 481 | int old_max_group_sockets_; |
| 482 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 483 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 484 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 485 | namespace { |
| 486 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 487 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 488 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 489 | BeforeHeadersSentHandler() |
| 490 | : observed_before_headers_sent_with_proxy_(false), |
| 491 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 492 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 493 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 494 | HttpRequestHeaders* request_headers) { |
| 495 | observed_before_headers_sent_ = true; |
| 496 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 497 | !proxy_info.is_quic()) { |
| 498 | return; |
| 499 | } |
| 500 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 501 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 502 | } |
| 503 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 504 | bool observed_before_headers_sent_with_proxy() const { |
| 505 | return observed_before_headers_sent_with_proxy_; |
| 506 | } |
| 507 | |
| 508 | bool observed_before_headers_sent() const { |
| 509 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | std::string observed_proxy_server_uri() const { |
| 513 | return observed_proxy_server_uri_; |
| 514 | } |
| 515 | |
| 516 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 517 | bool observed_before_headers_sent_with_proxy_; |
| 518 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 519 | std::string observed_proxy_server_uri_; |
| 520 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 521 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 522 | }; |
| 523 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 524 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 525 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 526 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 527 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 528 | const int sizeof_row = strlen(row); |
| 529 | const int num_rows = static_cast<int>( |
| 530 | ceil(static_cast<float>(size) / sizeof_row)); |
| 531 | const int sizeof_data = num_rows * sizeof_row; |
| 532 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 533 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 534 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 535 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 536 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 537 | } |
| 538 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 539 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 540 | uint64_t MockGetMSTime() { |
| 541 | // Tue, 23 May 2017 20:13:07 +0000 |
| 542 | return 131400439870000000; |
| 543 | } |
| 544 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 545 | // Alternative functions that eliminate randomness and dependency on the local |
| 546 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 547 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 548 | // This is set to 0xaa because the client challenge for testing in |
| 549 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 550 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 551 | } |
| 552 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 553 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 554 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 555 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 556 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 557 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 558 | template<typename ParentPool> |
| 559 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 560 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 561 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 562 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 563 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 564 | const std::string last_group_name_received() const { |
| 565 | return last_group_name_; |
| 566 | } |
| 567 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 568 | bool socket_requested() const { return socket_requested_; } |
| 569 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 570 | int RequestSocket(const std::string& group_name, |
| 571 | const void* socket_params, |
| 572 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 573 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 574 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 575 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 576 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 577 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 578 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 579 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 580 | return ERR_IO_PENDING; |
| 581 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 582 | void CancelRequest(const std::string& group_name, |
| 583 | ClientSocketHandle* handle) override {} |
| 584 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 585 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 586 | int id) override {} |
| 587 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 588 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 589 | int IdleSocketCount() const override { return 0; } |
| 590 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 591 | return 0; |
| 592 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 593 | LoadState GetLoadState(const std::string& group_name, |
| 594 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 595 | return LOAD_STATE_IDLE; |
| 596 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 597 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 598 | return base::TimeDelta(); |
| 599 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 600 | |
| 601 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 602 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 603 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 604 | }; |
| 605 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 606 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 607 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 608 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 609 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 610 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 611 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 612 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 613 | CaptureGroupNameSSLSocketPool; |
| 614 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 615 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 616 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 617 | HostResolver* host_resolver, |
| 618 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 619 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 620 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 621 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 622 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 623 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 624 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 625 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 626 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 627 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 628 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 629 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 630 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 631 | : SSLClientSocketPool(0, |
| 632 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 633 | cert_verifier, |
| 634 | NULL, |
| 635 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 636 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 637 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 638 | std::string(), |
| 639 | NULL, |
| 640 | NULL, |
| 641 | NULL, |
| 642 | NULL, |
| 643 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 644 | NULL) { |
| 645 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 646 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 647 | //----------------------------------------------------------------------------- |
| 648 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 649 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 650 | // configured for common cases. |
| 651 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 652 | if (!auth_challenge) |
| 653 | return false; |
| 654 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 655 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 656 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 657 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 658 | return true; |
| 659 | } |
| 660 | |
| 661 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 662 | if (!auth_challenge) |
| 663 | return false; |
| 664 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 665 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 666 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 667 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 668 | return true; |
| 669 | } |
| 670 | |
| 671 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 672 | if (!auth_challenge) |
| 673 | return false; |
| 674 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 675 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 676 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 677 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 678 | return true; |
| 679 | } |
| 680 | |
| 681 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 682 | if (!auth_challenge) |
| 683 | return false; |
| 684 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 685 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 686 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 687 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 688 | return true; |
| 689 | } |
| 690 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 691 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 692 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 693 | if (!auth_challenge) |
| 694 | return false; |
| 695 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 696 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 697 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 698 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 699 | return true; |
| 700 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 701 | |
| 702 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 703 | if (!auth_challenge) |
| 704 | return false; |
| 705 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 706 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 707 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 708 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 709 | return true; |
| 710 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 711 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 712 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 713 | } // namespace |
| 714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 715 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 718 | } |
| 719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 720 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 721 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 722 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 723 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 725 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 726 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 727 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 728 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 729 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 730 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 731 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 732 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 733 | |
| 734 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 738 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 739 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 740 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 741 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 742 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 743 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 744 | EXPECT_THAT(out.rv, IsOk()); |
| 745 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 746 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 747 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 748 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 749 | } |
| 750 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 751 | // Response with no status line, and a weird port. Should fail by default. |
| 752 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 753 | MockRead data_reads[] = { |
| 754 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 755 | }; |
| 756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 757 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 759 | |
| 760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 761 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 762 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 763 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 764 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 765 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 766 | request.method = "GET"; |
| 767 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 768 | request.traffic_annotation = |
| 769 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 770 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 771 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 772 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 773 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 774 | } |
| 775 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 776 | // Tests that request info can be destroyed after the headers phase is complete. |
| 777 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 779 | auto trans = |
| 780 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 781 | |
| 782 | MockRead data_reads[] = { |
| 783 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 784 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 785 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 786 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 788 | |
| 789 | TestCompletionCallback callback; |
| 790 | |
| 791 | { |
| 792 | auto request = std::make_unique<HttpRequestInfo>(); |
| 793 | request->method = "GET"; |
| 794 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 795 | request->traffic_annotation = |
| 796 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 797 | |
| 798 | int rv = |
| 799 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 800 | |
| 801 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 802 | } // Let request info be destroyed. |
| 803 | |
| 804 | trans.reset(); |
| 805 | } |
| 806 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 807 | // Response with no status line, and a weird port. Option to allow weird ports |
| 808 | // enabled. |
| 809 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 810 | MockRead data_reads[] = { |
| 811 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 812 | }; |
| 813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 814 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 816 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 818 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 819 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 820 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 821 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 822 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 823 | request.method = "GET"; |
| 824 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 825 | request.traffic_annotation = |
| 826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 827 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 828 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 829 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 831 | |
| 832 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 833 | ASSERT_TRUE(info->headers); |
| 834 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 835 | |
| 836 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 837 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 838 | } |
| 839 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 840 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 841 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 843 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 844 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 845 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 846 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 847 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 848 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 849 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 850 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 851 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 855 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 856 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 857 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 859 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 860 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 861 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 862 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 863 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 864 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 865 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 869 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 870 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 871 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 872 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 873 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 874 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 875 | EXPECT_THAT(out.rv, IsOk()); |
| 876 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 877 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 878 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 879 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 883 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 884 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 885 | MockRead("\n"), |
| 886 | MockRead("\n"), |
| 887 | MockRead("Q"), |
| 888 | MockRead("J"), |
| 889 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 890 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 891 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 892 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 893 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 894 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 895 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 896 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 897 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 901 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 902 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 903 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 904 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 905 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 906 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 907 | EXPECT_THAT(out.rv, IsOk()); |
| 908 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 909 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 910 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 911 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 912 | } |
| 913 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 914 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 915 | // persistent connection. The response should still terminate since a 204 |
| 916 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 917 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 918 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 919 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 920 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 921 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 922 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 923 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 924 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 925 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 926 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 927 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 928 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 929 | int64_t response_size = reads_size - strlen(junk); |
| 930 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 931 | } |
| 932 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 933 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 934 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 935 | std::string final_chunk = "0\r\n\r\n"; |
| 936 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 937 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 938 | MockRead data_reads[] = { |
| 939 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 940 | MockRead("5\r\nHello\r\n"), |
| 941 | MockRead("1\r\n"), |
| 942 | MockRead(" \r\n"), |
| 943 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 944 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 946 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 947 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 948 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 949 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 950 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 951 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 952 | int64_t response_size = reads_size - extra_data.size(); |
| 953 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 954 | } |
| 955 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 956 | // Next tests deal with http://crbug.com/56344. |
| 957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 958 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 959 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 960 | MockRead data_reads[] = { |
| 961 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 962 | MockRead("Content-Length: 10\r\n"), |
| 963 | MockRead("Content-Length: 5\r\n\r\n"), |
| 964 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 965 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 966 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 967 | } |
| 968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 969 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 970 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 971 | MockRead data_reads[] = { |
| 972 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 973 | MockRead("Content-Length: 5\r\n"), |
| 974 | MockRead("Content-Length: 5\r\n\r\n"), |
| 975 | MockRead("Hello"), |
| 976 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 977 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 978 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 979 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 980 | EXPECT_EQ("Hello", out.response_data); |
| 981 | } |
| 982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 983 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 984 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 985 | // More than 2 dupes. |
| 986 | { |
| 987 | MockRead data_reads[] = { |
| 988 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 989 | MockRead("Content-Length: 5\r\n"), |
| 990 | MockRead("Content-Length: 5\r\n"), |
| 991 | MockRead("Content-Length: 5\r\n\r\n"), |
| 992 | MockRead("Hello"), |
| 993 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 994 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 995 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 996 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 997 | EXPECT_EQ("Hello", out.response_data); |
| 998 | } |
| 999 | // HTTP/1.0 |
| 1000 | { |
| 1001 | MockRead data_reads[] = { |
| 1002 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1003 | MockRead("Content-Length: 5\r\n"), |
| 1004 | MockRead("Content-Length: 5\r\n"), |
| 1005 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1006 | MockRead("Hello"), |
| 1007 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1008 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1009 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1010 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1011 | EXPECT_EQ("Hello", out.response_data); |
| 1012 | } |
| 1013 | // 2 dupes and one mismatched. |
| 1014 | { |
| 1015 | MockRead data_reads[] = { |
| 1016 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1017 | MockRead("Content-Length: 10\r\n"), |
| 1018 | MockRead("Content-Length: 10\r\n"), |
| 1019 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1020 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1021 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1022 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1023 | } |
| 1024 | } |
| 1025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1026 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1027 | MultipleContentLengthHeadersTransferEncoding) { |
| 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1030 | MockRead("Content-Length: 666\r\n"), |
| 1031 | MockRead("Content-Length: 1337\r\n"), |
| 1032 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1033 | MockRead("5\r\nHello\r\n"), |
| 1034 | MockRead("1\r\n"), |
| 1035 | MockRead(" \r\n"), |
| 1036 | MockRead("5\r\nworld\r\n"), |
| 1037 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1038 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1040 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1041 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1042 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1043 | EXPECT_EQ("Hello world", out.response_data); |
| 1044 | } |
| 1045 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1046 | // Next tests deal with http://crbug.com/98895. |
| 1047 | |
| 1048 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1049 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1050 | MockRead data_reads[] = { |
| 1051 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1052 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1053 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1054 | MockRead("Hello"), |
| 1055 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1056 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1057 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1058 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1059 | EXPECT_EQ("Hello", out.response_data); |
| 1060 | } |
| 1061 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1062 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1063 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1064 | MockRead data_reads[] = { |
| 1065 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1066 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1067 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1072 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1073 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1078 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1079 | MockRead data_reads[] = { |
| 1080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1081 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1082 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1084 | MockRead("Hello"), |
| 1085 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1086 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1087 | EXPECT_THAT(out.rv, |
| 1088 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1089 | } |
| 1090 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1091 | // Checks that two identical Location headers result in no error. |
| 1092 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1093 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1094 | MockRead data_reads[] = { |
| 1095 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1096 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1097 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1098 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1099 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1100 | }; |
| 1101 | |
| 1102 | HttpRequestInfo request; |
| 1103 | request.method = "GET"; |
| 1104 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1105 | request.traffic_annotation = |
| 1106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1107 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1108 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1109 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1111 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1113 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1114 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1116 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1118 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1119 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1121 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1122 | ASSERT_TRUE(response); |
| 1123 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1124 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1125 | std::string url; |
| 1126 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1127 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1128 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1129 | } |
| 1130 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1131 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1132 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1133 | MockRead data_reads[] = { |
| 1134 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1135 | MockRead("Location: http://good.com/\r\n"), |
| 1136 | MockRead("Location: http://evil.com/\r\n"), |
| 1137 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1138 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1140 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1141 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1142 | } |
| 1143 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1144 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1145 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1146 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1147 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1148 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1149 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1150 | request.traffic_annotation = |
| 1151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1154 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1155 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1156 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1157 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1158 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1159 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1160 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1161 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1162 | "Host: www.example.org\r\n" |
| 1163 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1164 | }; |
| 1165 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1166 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1167 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1168 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1169 | // No response body because the test stops reading here. |
| 1170 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1171 | }; |
| 1172 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1173 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1174 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1176 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1177 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1178 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1179 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1180 | |
| 1181 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1182 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1184 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1185 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1186 | |
| 1187 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1188 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1189 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1190 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1191 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1192 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1193 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1194 | |
| 1195 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1196 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1197 | bool has_server_header = response->headers->EnumerateHeader( |
| 1198 | &iter, "Server", &server_header); |
| 1199 | EXPECT_TRUE(has_server_header); |
| 1200 | EXPECT_EQ("Blah", server_header); |
| 1201 | |
| 1202 | // Reading should give EOF right away, since there is no message body |
| 1203 | // (despite non-zero content-length). |
| 1204 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1205 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1207 | EXPECT_EQ("", response_data); |
| 1208 | } |
| 1209 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1210 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1212 | |
| 1213 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1214 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1215 | MockRead("hello"), |
| 1216 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1217 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1218 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1219 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1220 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1221 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1222 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1223 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1224 | "hello", "world" |
| 1225 | }; |
| 1226 | |
| 1227 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1228 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1229 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1230 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1231 | request.traffic_annotation = |
| 1232 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1236 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1237 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1238 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1240 | |
| 1241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1242 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1244 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1245 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1246 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1247 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1248 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1249 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1250 | |
| 1251 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1252 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1254 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1255 | } |
| 1256 | } |
| 1257 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1258 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1259 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1260 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1261 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1262 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1263 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1264 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1265 | request.method = "POST"; |
| 1266 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1267 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1268 | request.traffic_annotation = |
| 1269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1270 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1271 | // Check the upload progress returned before initialization is correct. |
| 1272 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1273 | EXPECT_EQ(0u, progress.size()); |
| 1274 | EXPECT_EQ(0u, progress.position()); |
| 1275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1278 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1279 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1280 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1281 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1282 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1283 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1285 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1287 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1288 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1290 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | |
| 1293 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1294 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1296 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1297 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1299 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1300 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | |
| 1302 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1303 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1305 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | } |
| 1307 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1308 | // This test is almost the same as Ignores100 above, but the response contains |
| 1309 | // 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] | 1310 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1311 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1312 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1313 | request.method = "GET"; |
| 1314 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1315 | request.traffic_annotation = |
| 1316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1317 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1319 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1320 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1321 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1322 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1323 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1324 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1325 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1326 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1327 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1329 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1330 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1334 | |
| 1335 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1338 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1339 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1340 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1341 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1343 | |
| 1344 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1345 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1346 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1347 | EXPECT_EQ("hello world", response_data); |
| 1348 | } |
| 1349 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1350 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1351 | HttpRequestInfo request; |
| 1352 | request.method = "POST"; |
| 1353 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1354 | request.traffic_annotation = |
| 1355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1356 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1357 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1359 | |
| 1360 | MockRead data_reads[] = { |
| 1361 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1362 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1363 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1364 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1365 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1366 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1367 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1371 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1374 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1375 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1376 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1377 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1378 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1379 | } |
| 1380 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1381 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1382 | HttpRequestInfo request; |
| 1383 | request.method = "POST"; |
| 1384 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1385 | request.traffic_annotation = |
| 1386 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1390 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1391 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1392 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1393 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1394 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1397 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1398 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1399 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1401 | |
| 1402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1403 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1404 | } |
| 1405 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1406 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1407 | const MockWrite* write_failure, |
| 1408 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1409 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1410 | request.method = "GET"; |
| 1411 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1412 | request.traffic_annotation = |
| 1413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1414 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1415 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1416 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1418 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1419 | // Written data for successfully sending both requests. |
| 1420 | MockWrite data1_writes[] = { |
| 1421 | MockWrite("GET / HTTP/1.1\r\n" |
| 1422 | "Host: www.foo.com\r\n" |
| 1423 | "Connection: keep-alive\r\n\r\n"), |
| 1424 | MockWrite("GET / HTTP/1.1\r\n" |
| 1425 | "Host: www.foo.com\r\n" |
| 1426 | "Connection: keep-alive\r\n\r\n") |
| 1427 | }; |
| 1428 | |
| 1429 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1430 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1431 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1432 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1433 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1434 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1435 | |
| 1436 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1437 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1438 | data1_writes[1] = *write_failure; |
| 1439 | } else { |
| 1440 | ASSERT_TRUE(read_failure); |
| 1441 | data1_reads[2] = *read_failure; |
| 1442 | } |
| 1443 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1444 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1445 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1446 | |
| 1447 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1448 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1449 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1450 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1451 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1452 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1453 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1454 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1455 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1456 | "hello", "world" |
| 1457 | }; |
| 1458 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1459 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1460 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1461 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1462 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1463 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1464 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1465 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1467 | |
| 1468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1469 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1470 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1471 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1472 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1473 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1474 | if (i == 0) { |
| 1475 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1476 | } else { |
| 1477 | // The second request should be using a new socket. |
| 1478 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1479 | } |
| 1480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1481 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1482 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1484 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1485 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1486 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1487 | |
| 1488 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1489 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1491 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1492 | } |
| 1493 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1494 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1495 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1496 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1497 | const MockRead* read_failure, |
| 1498 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1499 | HttpRequestInfo request; |
| 1500 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1501 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1502 | request.traffic_annotation = |
| 1503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1504 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1505 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1506 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1508 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1509 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1510 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1511 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1512 | ssl1.next_proto = kProtoHTTP2; |
| 1513 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1514 | } |
| 1515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1517 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1518 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1519 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1520 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1521 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1522 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1523 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1524 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1525 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1526 | // HTTP/1.1 versions of the request and response. |
| 1527 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1528 | "Host: www.foo.com\r\n" |
| 1529 | "Connection: keep-alive\r\n\r\n"; |
| 1530 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1531 | const char kHttpData[] = "hello"; |
| 1532 | |
| 1533 | std::vector<MockRead> data1_reads; |
| 1534 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1535 | if (write_failure) { |
| 1536 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1537 | data1_writes.push_back(*write_failure); |
| 1538 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1539 | } else { |
| 1540 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1541 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1542 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1543 | } else { |
| 1544 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1545 | } |
| 1546 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1547 | } |
| 1548 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1549 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1550 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1551 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1552 | std::vector<MockRead> data2_reads; |
| 1553 | std::vector<MockWrite> data2_writes; |
| 1554 | |
| 1555 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1556 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1557 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1558 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1559 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1560 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1561 | } else { |
| 1562 | data2_writes.push_back( |
| 1563 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1564 | |
| 1565 | data2_reads.push_back( |
| 1566 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1567 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1568 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1569 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1570 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1571 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1572 | |
| 1573 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1574 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1575 | // Wait for the preconnect to complete. |
| 1576 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1577 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1578 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1579 | |
| 1580 | // Make the request. |
| 1581 | TestCompletionCallback callback; |
| 1582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1585 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | |
| 1588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1589 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1590 | |
| 1591 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1592 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1593 | TestLoadTimingNotReused( |
| 1594 | load_timing_info, |
| 1595 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1597 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1598 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1599 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1600 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1601 | if (response->was_fetched_via_spdy) { |
| 1602 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1603 | } else { |
| 1604 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1605 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1606 | |
| 1607 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1608 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1609 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1610 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1611 | } |
| 1612 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1613 | // Test that we do not retry indefinitely when a server sends an error like |
| 1614 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1615 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1616 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1617 | HttpRequestInfo request; |
| 1618 | request.method = "GET"; |
| 1619 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1620 | request.traffic_annotation = |
| 1621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1622 | |
| 1623 | // Check whether we give up after the third try. |
| 1624 | |
| 1625 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1626 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1627 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1628 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1629 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1630 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1631 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1632 | |
| 1633 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1634 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1635 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1636 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1637 | |
| 1638 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1639 | AddSSLSocketData(); |
| 1640 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1641 | AddSSLSocketData(); |
| 1642 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1643 | AddSSLSocketData(); |
| 1644 | |
| 1645 | TestCompletionCallback callback; |
| 1646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1648 | |
| 1649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1651 | |
| 1652 | rv = callback.WaitForResult(); |
| 1653 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1654 | } |
| 1655 | |
| 1656 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1657 | HttpRequestInfo request; |
| 1658 | request.method = "GET"; |
| 1659 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1660 | request.traffic_annotation = |
| 1661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1662 | |
| 1663 | // Check whether we try atleast thrice before giving up. |
| 1664 | |
| 1665 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1666 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1667 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1668 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1669 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1670 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1671 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1672 | |
| 1673 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1674 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1675 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1676 | spdy::SpdySerializedFrame spdy_data( |
| 1677 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1678 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1679 | CreateMockRead(spdy_data, 2)}; |
| 1680 | |
| 1681 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1682 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1683 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1684 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1685 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1686 | |
| 1687 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1688 | AddSSLSocketData(); |
| 1689 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1690 | AddSSLSocketData(); |
| 1691 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1692 | AddSSLSocketData(); |
| 1693 | |
| 1694 | TestCompletionCallback callback; |
| 1695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1697 | |
| 1698 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1700 | |
| 1701 | rv = callback.WaitForResult(); |
| 1702 | EXPECT_THAT(rv, IsOk()); |
| 1703 | } |
| 1704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1705 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1706 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1707 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1708 | } |
| 1709 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1710 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1711 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1712 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1713 | } |
| 1714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1715 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1716 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1717 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1718 | } |
| 1719 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1720 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1721 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1722 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1723 | MockRead read_failure(SYNCHRONOUS, |
| 1724 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1725 | "Connection: Keep-Alive\r\n" |
| 1726 | "Content-Length: 6\r\n\r\n" |
| 1727 | "Pickle"); |
| 1728 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1729 | } |
| 1730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1731 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1732 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1733 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1734 | } |
| 1735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1736 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1737 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1738 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1739 | } |
| 1740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1742 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1743 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1744 | } |
| 1745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1746 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1747 | MockRead read_failure(ASYNC, OK); // EOF |
| 1748 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1749 | } |
| 1750 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1751 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1752 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1753 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1754 | MockRead read_failure(SYNCHRONOUS, |
| 1755 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1756 | "Connection: Keep-Alive\r\n" |
| 1757 | "Content-Length: 6\r\n\r\n" |
| 1758 | "Pickle"); |
| 1759 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1760 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1761 | } |
| 1762 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1763 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1764 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1765 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1766 | } |
| 1767 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1768 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1769 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1770 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1771 | } |
| 1772 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1773 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1774 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1775 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1776 | } |
| 1777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1778 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1779 | MockRead read_failure(ASYNC, OK); // EOF |
| 1780 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1781 | } |
| 1782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1783 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1784 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1785 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1786 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1787 | request.traffic_annotation = |
| 1788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1792 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1793 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1794 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1795 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1796 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1798 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1799 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1800 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1802 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1803 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1804 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1806 | |
| 1807 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1808 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1809 | |
| 1810 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1811 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1812 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | // What do various browsers do when the server closes a non-keepalive |
| 1816 | // connection without sending any response header or body? |
| 1817 | // |
| 1818 | // IE7: error page |
| 1819 | // Safari 3.1.2 (Windows): error page |
| 1820 | // Firefox 3.0.1: blank page |
| 1821 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1822 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1823 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1824 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1825 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1826 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1827 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1828 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1829 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1830 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1831 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1832 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1833 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1834 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1835 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1836 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1837 | // destructor in such situations. |
| 1838 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1839 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1840 | HttpRequestInfo request; |
| 1841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1842 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1843 | request.traffic_annotation = |
| 1844 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1847 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1848 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1849 | |
| 1850 | MockRead data_reads[] = { |
| 1851 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1852 | MockRead("Connection: keep-alive\r\n"), |
| 1853 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1854 | MockRead("hello"), |
| 1855 | MockRead(SYNCHRONOUS, 0), |
| 1856 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1857 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1859 | |
| 1860 | TestCompletionCallback callback; |
| 1861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1862 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | |
| 1865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1867 | |
| 1868 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1869 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1870 | if (rv == ERR_IO_PENDING) |
| 1871 | rv = callback.WaitForResult(); |
| 1872 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1873 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1874 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1875 | |
| 1876 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1877 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1878 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1879 | } |
| 1880 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1881 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1882 | HttpRequestInfo request; |
| 1883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1884 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1885 | request.traffic_annotation = |
| 1886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1889 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1890 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1891 | |
| 1892 | MockRead data_reads[] = { |
| 1893 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1894 | MockRead("Connection: keep-alive\r\n"), |
| 1895 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1896 | MockRead(SYNCHRONOUS, 0), |
| 1897 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1898 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1899 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1900 | |
| 1901 | TestCompletionCallback callback; |
| 1902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1903 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1905 | |
| 1906 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1908 | |
| 1909 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1910 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1911 | if (rv == ERR_IO_PENDING) |
| 1912 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1913 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1914 | |
| 1915 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1916 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1917 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1918 | } |
| 1919 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1920 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1921 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1922 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1923 | HttpRequestInfo request; |
| 1924 | request.method = "GET"; |
| 1925 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 1926 | request.traffic_annotation = |
| 1927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1928 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1929 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1930 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1932 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1933 | const char* request_data = |
| 1934 | "GET / HTTP/1.1\r\n" |
| 1935 | "Host: www.foo.com\r\n" |
| 1936 | "Connection: keep-alive\r\n\r\n"; |
| 1937 | MockWrite data_writes[] = { |
| 1938 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1939 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1940 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1941 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1942 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1943 | }; |
| 1944 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1945 | // Note that because all these reads happen in the same |
| 1946 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1947 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1948 | MockRead data_reads[] = { |
| 1949 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1950 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1951 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1952 | MockRead(ASYNC, 7, |
| 1953 | "HTTP/1.1 302 Found\r\n" |
| 1954 | "Content-Length: 0\r\n\r\n"), |
| 1955 | MockRead(ASYNC, 9, |
| 1956 | "HTTP/1.1 302 Found\r\n" |
| 1957 | "Content-Length: 5\r\n\r\n" |
| 1958 | "hello"), |
| 1959 | MockRead(ASYNC, 11, |
| 1960 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1961 | "Content-Length: 0\r\n\r\n"), |
| 1962 | MockRead(ASYNC, 13, |
| 1963 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1964 | "Content-Length: 5\r\n\r\n" |
| 1965 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1966 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1967 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1968 | // the set_busy_before_sync_reads(true) call, while the |
| 1969 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1970 | // reuseable. See http://crbug.com/544255. |
| 1971 | MockRead(ASYNC, 15, |
| 1972 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1973 | "Content-Length: 5\r\n\r\n"), |
| 1974 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1975 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1976 | MockRead(ASYNC, 18, |
| 1977 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1978 | "Content-Length: 5\r\n\r\n" |
| 1979 | "he"), |
| 1980 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1981 | |
| 1982 | // The body of the final request is actually read. |
| 1983 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1984 | MockRead(ASYNC, 22, "hello"), |
| 1985 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1986 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1987 | data.set_busy_before_sync_reads(true); |
| 1988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1989 | |
| 1990 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1991 | std::string response_lines[kNumUnreadBodies]; |
| 1992 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1993 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1994 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1995 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1996 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1997 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1998 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1999 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2000 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2001 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2002 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2003 | LoadTimingInfo load_timing_info; |
| 2004 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2005 | if (i == 0) { |
| 2006 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2007 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2008 | } else { |
| 2009 | TestLoadTimingReused(load_timing_info); |
| 2010 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2011 | } |
| 2012 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2013 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2014 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2015 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2016 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2017 | response_lines[i] = response->headers->GetStatusLine(); |
| 2018 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2019 | // Delete the transaction without reading the response bodies. Then spin |
| 2020 | // the message loop, so the response bodies are drained. |
| 2021 | trans.reset(); |
| 2022 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2023 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2024 | |
| 2025 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2026 | "HTTP/1.1 204 No Content", |
| 2027 | "HTTP/1.1 205 Reset Content", |
| 2028 | "HTTP/1.1 304 Not Modified", |
| 2029 | "HTTP/1.1 302 Found", |
| 2030 | "HTTP/1.1 302 Found", |
| 2031 | "HTTP/1.1 301 Moved Permanently", |
| 2032 | "HTTP/1.1 301 Moved Permanently", |
| 2033 | "HTTP/1.1 200 Hunky-Dory", |
| 2034 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2035 | }; |
| 2036 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2037 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2038 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2039 | |
| 2040 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2041 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2043 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2046 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2047 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2048 | ASSERT_TRUE(response); |
| 2049 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2050 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2051 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2052 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2053 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2054 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2055 | } |
| 2056 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2057 | // Sockets that receive extra data after a response is complete should not be |
| 2058 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2059 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2060 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2061 | MockWrite data_writes1[] = { |
| 2062 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2063 | "Host: www.borked.com\r\n" |
| 2064 | "Connection: keep-alive\r\n\r\n"), |
| 2065 | }; |
| 2066 | |
| 2067 | MockRead data_reads1[] = { |
| 2068 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2069 | "Connection: keep-alive\r\n" |
| 2070 | "Content-Length: 22\r\n\r\n" |
| 2071 | "This server is borked."), |
| 2072 | }; |
| 2073 | |
| 2074 | MockWrite data_writes2[] = { |
| 2075 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2076 | "Host: www.borked.com\r\n" |
| 2077 | "Connection: keep-alive\r\n\r\n"), |
| 2078 | }; |
| 2079 | |
| 2080 | MockRead data_reads2[] = { |
| 2081 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2082 | "Content-Length: 3\r\n\r\n" |
| 2083 | "foo"), |
| 2084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2085 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2086 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2087 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2088 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2089 | |
| 2090 | TestCompletionCallback callback; |
| 2091 | HttpRequestInfo request1; |
| 2092 | request1.method = "HEAD"; |
| 2093 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2094 | request1.traffic_annotation = |
| 2095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2096 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2097 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2098 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2099 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2100 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2101 | |
| 2102 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2103 | ASSERT_TRUE(response1); |
| 2104 | ASSERT_TRUE(response1->headers); |
| 2105 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2106 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2107 | |
| 2108 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2109 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2110 | EXPECT_EQ("", response_data1); |
| 2111 | // Deleting the transaction attempts to release the socket back into the |
| 2112 | // socket pool. |
| 2113 | trans1.reset(); |
| 2114 | |
| 2115 | HttpRequestInfo request2; |
| 2116 | request2.method = "GET"; |
| 2117 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2118 | request2.traffic_annotation = |
| 2119 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2120 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2121 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2122 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2123 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2124 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2125 | |
| 2126 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2127 | ASSERT_TRUE(response2); |
| 2128 | ASSERT_TRUE(response2->headers); |
| 2129 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2130 | |
| 2131 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2132 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2133 | EXPECT_EQ("foo", response_data2); |
| 2134 | } |
| 2135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2136 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2138 | MockWrite data_writes1[] = { |
| 2139 | MockWrite("GET / HTTP/1.1\r\n" |
| 2140 | "Host: www.borked.com\r\n" |
| 2141 | "Connection: keep-alive\r\n\r\n"), |
| 2142 | }; |
| 2143 | |
| 2144 | MockRead data_reads1[] = { |
| 2145 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2146 | "Connection: keep-alive\r\n" |
| 2147 | "Content-Length: 22\r\n\r\n" |
| 2148 | "This server is borked." |
| 2149 | "Bonus data!"), |
| 2150 | }; |
| 2151 | |
| 2152 | MockWrite data_writes2[] = { |
| 2153 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2154 | "Host: www.borked.com\r\n" |
| 2155 | "Connection: keep-alive\r\n\r\n"), |
| 2156 | }; |
| 2157 | |
| 2158 | MockRead data_reads2[] = { |
| 2159 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2160 | "Content-Length: 3\r\n\r\n" |
| 2161 | "foo"), |
| 2162 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2163 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2164 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2165 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2166 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2167 | |
| 2168 | TestCompletionCallback callback; |
| 2169 | HttpRequestInfo request1; |
| 2170 | request1.method = "GET"; |
| 2171 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2172 | request1.traffic_annotation = |
| 2173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2174 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2175 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2176 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2177 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2178 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2179 | |
| 2180 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2181 | ASSERT_TRUE(response1); |
| 2182 | ASSERT_TRUE(response1->headers); |
| 2183 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2184 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2185 | |
| 2186 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2187 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2188 | EXPECT_EQ("This server is borked.", response_data1); |
| 2189 | // Deleting the transaction attempts to release the socket back into the |
| 2190 | // socket pool. |
| 2191 | trans1.reset(); |
| 2192 | |
| 2193 | HttpRequestInfo request2; |
| 2194 | request2.method = "GET"; |
| 2195 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2196 | request2.traffic_annotation = |
| 2197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2198 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2199 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2200 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2201 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2202 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2203 | |
| 2204 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2205 | ASSERT_TRUE(response2); |
| 2206 | ASSERT_TRUE(response2->headers); |
| 2207 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2208 | |
| 2209 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2210 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2211 | EXPECT_EQ("foo", response_data2); |
| 2212 | } |
| 2213 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2214 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2215 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2216 | MockWrite data_writes1[] = { |
| 2217 | MockWrite("GET / HTTP/1.1\r\n" |
| 2218 | "Host: www.borked.com\r\n" |
| 2219 | "Connection: keep-alive\r\n\r\n"), |
| 2220 | }; |
| 2221 | |
| 2222 | MockRead data_reads1[] = { |
| 2223 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2224 | "Connection: keep-alive\r\n" |
| 2225 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2226 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2227 | MockRead("0\r\n\r\nBonus data!"), |
| 2228 | }; |
| 2229 | |
| 2230 | MockWrite data_writes2[] = { |
| 2231 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2232 | "Host: www.borked.com\r\n" |
| 2233 | "Connection: keep-alive\r\n\r\n"), |
| 2234 | }; |
| 2235 | |
| 2236 | MockRead data_reads2[] = { |
| 2237 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2238 | "Content-Length: 3\r\n\r\n" |
| 2239 | "foo"), |
| 2240 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2241 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2243 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2244 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2245 | |
| 2246 | TestCompletionCallback callback; |
| 2247 | HttpRequestInfo request1; |
| 2248 | request1.method = "GET"; |
| 2249 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2250 | request1.traffic_annotation = |
| 2251 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2252 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2253 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2254 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2255 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2256 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2257 | |
| 2258 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2259 | ASSERT_TRUE(response1); |
| 2260 | ASSERT_TRUE(response1->headers); |
| 2261 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2262 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2263 | |
| 2264 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2265 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2266 | EXPECT_EQ("This server is borked.", response_data1); |
| 2267 | // Deleting the transaction attempts to release the socket back into the |
| 2268 | // socket pool. |
| 2269 | trans1.reset(); |
| 2270 | |
| 2271 | HttpRequestInfo request2; |
| 2272 | request2.method = "GET"; |
| 2273 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2274 | request2.traffic_annotation = |
| 2275 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2276 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2277 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2279 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2280 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2281 | |
| 2282 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2283 | ASSERT_TRUE(response2); |
| 2284 | ASSERT_TRUE(response2->headers); |
| 2285 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2286 | |
| 2287 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2288 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2289 | EXPECT_EQ("foo", response_data2); |
| 2290 | } |
| 2291 | |
| 2292 | // This is a little different from the others - it tests the case that the |
| 2293 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2294 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2295 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2296 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2298 | MockWrite data_writes1[] = { |
| 2299 | MockWrite("GET / HTTP/1.1\r\n" |
| 2300 | "Host: www.borked.com\r\n" |
| 2301 | "Connection: keep-alive\r\n\r\n"), |
| 2302 | }; |
| 2303 | |
| 2304 | MockRead data_reads1[] = { |
| 2305 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2306 | "Connection: keep-alive\r\n" |
| 2307 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2308 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2309 | MockRead("0\r\n\r\nBonus data!"), |
| 2310 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2311 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2312 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2313 | |
| 2314 | TestCompletionCallback callback; |
| 2315 | HttpRequestInfo request1; |
| 2316 | request1.method = "GET"; |
| 2317 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2318 | request1.traffic_annotation = |
| 2319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2320 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2321 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2322 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2323 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2324 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2325 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2326 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2327 | ASSERT_TRUE(response1); |
| 2328 | ASSERT_TRUE(response1->headers); |
| 2329 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2330 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2331 | |
| 2332 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2333 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2334 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2335 | |
| 2336 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2337 | // socket can't be reused, rather than returning it to the socket pool. |
| 2338 | base::RunLoop().RunUntilIdle(); |
| 2339 | |
| 2340 | // There should be no idle sockets in the pool. |
| 2341 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2342 | } |
| 2343 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2344 | // Test the request-challenge-retry sequence for basic auth. |
| 2345 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2346 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2347 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2348 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2349 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2350 | request.traffic_annotation = |
| 2351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2352 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2353 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2354 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2357 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2358 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2359 | MockWrite( |
| 2360 | "GET / HTTP/1.1\r\n" |
| 2361 | "Host: www.example.org\r\n" |
| 2362 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2363 | }; |
| 2364 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2365 | MockRead data_reads1[] = { |
| 2366 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2367 | // Give a couple authenticate options (only the middle one is actually |
| 2368 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2369 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2370 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2371 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2372 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2373 | // Large content-length -- won't matter, as connection will be reset. |
| 2374 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2375 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2376 | }; |
| 2377 | |
| 2378 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2379 | // be issuing -- the final header line contains the credentials. |
| 2380 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2381 | MockWrite( |
| 2382 | "GET / HTTP/1.1\r\n" |
| 2383 | "Host: www.example.org\r\n" |
| 2384 | "Connection: keep-alive\r\n" |
| 2385 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2386 | }; |
| 2387 | |
| 2388 | // Lastly, the server responds with the actual content. |
| 2389 | MockRead data_reads2[] = { |
| 2390 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2392 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2394 | }; |
| 2395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2396 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2397 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2398 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2399 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2401 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2402 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2403 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2404 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2405 | |
| 2406 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2407 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2408 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2409 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2410 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2411 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2412 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2413 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2414 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2415 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2416 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2418 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2419 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2420 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2422 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2424 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2426 | |
| 2427 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2429 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2430 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2431 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2432 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2433 | // The load timing after restart should have a new socket ID, and times after |
| 2434 | // those of the first load timing. |
| 2435 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2436 | load_timing_info2.connect_timing.connect_start); |
| 2437 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2438 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2439 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2440 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2441 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2442 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2444 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2445 | ASSERT_TRUE(response); |
| 2446 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2447 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2448 | } |
| 2449 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2450 | // Test the request-challenge-retry sequence for basic auth. |
| 2451 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2452 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2453 | HttpRequestInfo request; |
| 2454 | request.method = "GET"; |
| 2455 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2456 | request.traffic_annotation = |
| 2457 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2458 | |
| 2459 | TestNetLog log; |
| 2460 | MockHostResolver* resolver = new MockHostResolver(); |
| 2461 | session_deps_.net_log = &log; |
| 2462 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2463 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2465 | |
| 2466 | resolver->rules()->ClearRules(); |
| 2467 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2468 | |
| 2469 | MockWrite data_writes1[] = { |
| 2470 | MockWrite("GET / HTTP/1.1\r\n" |
| 2471 | "Host: www.example.org\r\n" |
| 2472 | "Connection: keep-alive\r\n\r\n"), |
| 2473 | }; |
| 2474 | |
| 2475 | MockRead data_reads1[] = { |
| 2476 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2477 | // Give a couple authenticate options (only the middle one is actually |
| 2478 | // supported). |
| 2479 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2480 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2481 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2482 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2483 | // Large content-length -- won't matter, as connection will be reset. |
| 2484 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2485 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2486 | }; |
| 2487 | |
| 2488 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2489 | // be issuing -- the final header line contains the credentials. |
| 2490 | MockWrite data_writes2[] = { |
| 2491 | MockWrite("GET / HTTP/1.1\r\n" |
| 2492 | "Host: www.example.org\r\n" |
| 2493 | "Connection: keep-alive\r\n" |
| 2494 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2495 | }; |
| 2496 | |
| 2497 | // Lastly, the server responds with the actual content. |
| 2498 | MockRead data_reads2[] = { |
| 2499 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2500 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2501 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2502 | }; |
| 2503 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2504 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2505 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2506 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2507 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2508 | |
| 2509 | TestCompletionCallback callback1; |
| 2510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2511 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2512 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2513 | |
| 2514 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2515 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2516 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2517 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2518 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2519 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2520 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2521 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2523 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2524 | ASSERT_TRUE(response); |
| 2525 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2526 | |
| 2527 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2528 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2529 | ASSERT_FALSE(endpoint.address().empty()); |
| 2530 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2531 | |
| 2532 | resolver->rules()->ClearRules(); |
| 2533 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2534 | |
| 2535 | TestCompletionCallback callback2; |
| 2536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2537 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2538 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2539 | |
| 2540 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2541 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2542 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2543 | // The load timing after restart should have a new socket ID, and times after |
| 2544 | // those of the first load timing. |
| 2545 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2546 | load_timing_info2.connect_timing.connect_start); |
| 2547 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2548 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2549 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2550 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2551 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2552 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2555 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2556 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2557 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2559 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2560 | ASSERT_FALSE(endpoint.address().empty()); |
| 2561 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2562 | } |
| 2563 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2564 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2565 | // will eventually give up. |
| 2566 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2567 | HttpRequestInfo request; |
| 2568 | request.method = "GET"; |
| 2569 | request.url = GURL("http://www.example.org/"); |
| 2570 | request.traffic_annotation = |
| 2571 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2572 | |
| 2573 | TestNetLog log; |
| 2574 | session_deps_.net_log = &log; |
| 2575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2576 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2577 | |
| 2578 | MockWrite data_writes[] = { |
| 2579 | MockWrite("GET / HTTP/1.1\r\n" |
| 2580 | "Host: www.example.org\r\n" |
| 2581 | "Connection: keep-alive\r\n\r\n"), |
| 2582 | }; |
| 2583 | |
| 2584 | MockRead data_reads[] = { |
| 2585 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2586 | // Give a couple authenticate options (only the middle one is actually |
| 2587 | // supported). |
| 2588 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2589 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2590 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2591 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2592 | // Large content-length -- won't matter, as connection will be reset. |
| 2593 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2594 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2595 | }; |
| 2596 | |
| 2597 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2598 | // be issuing -- the final header line contains the credentials. |
| 2599 | MockWrite data_writes_restart[] = { |
| 2600 | MockWrite("GET / HTTP/1.1\r\n" |
| 2601 | "Host: www.example.org\r\n" |
| 2602 | "Connection: keep-alive\r\n" |
| 2603 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2604 | }; |
| 2605 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2606 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2608 | |
| 2609 | TestCompletionCallback callback; |
| 2610 | int rv = callback.GetResult( |
| 2611 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2612 | |
| 2613 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2614 | for (int i = 0; i < 32; i++) { |
| 2615 | // Check the previous response was a 401. |
| 2616 | EXPECT_THAT(rv, IsOk()); |
| 2617 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2618 | ASSERT_TRUE(response); |
| 2619 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2620 | |
| 2621 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2622 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2623 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2624 | data_restarts.back().get()); |
| 2625 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2626 | callback.callback())); |
| 2627 | } |
| 2628 | |
| 2629 | // After too many tries, the transaction should have given up. |
| 2630 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2631 | } |
| 2632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2633 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2634 | HttpRequestInfo request; |
| 2635 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2636 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2637 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2638 | request.traffic_annotation = |
| 2639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2640 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2643 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2644 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2645 | MockWrite( |
| 2646 | "GET / HTTP/1.1\r\n" |
| 2647 | "Host: www.example.org\r\n" |
| 2648 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2649 | }; |
| 2650 | |
| 2651 | MockRead data_reads[] = { |
| 2652 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2653 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2654 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2655 | // Large content-length -- won't matter, as connection will be reset. |
| 2656 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2657 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2658 | }; |
| 2659 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2660 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2662 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2664 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2666 | |
| 2667 | rv = callback.WaitForResult(); |
| 2668 | EXPECT_EQ(0, rv); |
| 2669 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2670 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2671 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2672 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2673 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2675 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2676 | ASSERT_TRUE(response); |
| 2677 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2678 | } |
| 2679 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2681 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2682 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2683 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2684 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2685 | // reused. See http://crbug.com/544255. |
| 2686 | for (int i = 0; i < 2; ++i) { |
| 2687 | HttpRequestInfo request; |
| 2688 | request.method = "GET"; |
| 2689 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2690 | request.traffic_annotation = |
| 2691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2692 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2693 | TestNetLog log; |
| 2694 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2696 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2697 | MockWrite data_writes[] = { |
| 2698 | MockWrite(ASYNC, 0, |
| 2699 | "GET / HTTP/1.1\r\n" |
| 2700 | "Host: www.example.org\r\n" |
| 2701 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2704 | // be issuing -- the final header line contains the credentials. |
| 2705 | MockWrite(ASYNC, 6, |
| 2706 | "GET / HTTP/1.1\r\n" |
| 2707 | "Host: www.example.org\r\n" |
| 2708 | "Connection: keep-alive\r\n" |
| 2709 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2710 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2711 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2712 | MockRead data_reads[] = { |
| 2713 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2714 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2715 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2716 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2717 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2719 | // Lastly, the server responds with the actual content. |
| 2720 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2721 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2722 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2723 | MockRead(ASYNC, 10, "Hello"), |
| 2724 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2726 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2727 | data.set_busy_before_sync_reads(true); |
| 2728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2729 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2730 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2733 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2734 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2735 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2736 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2738 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2740 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2741 | ASSERT_TRUE(response); |
| 2742 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2743 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2744 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2746 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2747 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2748 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2749 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2750 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2751 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2752 | TestLoadTimingReused(load_timing_info2); |
| 2753 | // The load timing after restart should have the same socket ID, and times |
| 2754 | // those of the first load timing. |
| 2755 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2756 | load_timing_info2.send_start); |
| 2757 | 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] | 2758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2759 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2760 | ASSERT_TRUE(response); |
| 2761 | EXPECT_FALSE(response->auth_challenge); |
| 2762 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2763 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2764 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2765 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2766 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2767 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2768 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2769 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2770 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2771 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2775 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2776 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2777 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2778 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2779 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2780 | request.traffic_annotation = |
| 2781 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2784 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2785 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2786 | MockWrite("GET / HTTP/1.1\r\n" |
| 2787 | "Host: www.example.org\r\n" |
| 2788 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2790 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2791 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2792 | MockWrite("GET / HTTP/1.1\r\n" |
| 2793 | "Host: www.example.org\r\n" |
| 2794 | "Connection: keep-alive\r\n" |
| 2795 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | }; |
| 2797 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2798 | MockRead data_reads1[] = { |
| 2799 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2800 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2801 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
| 2803 | // Lastly, the server responds with the actual content. |
| 2804 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2805 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2806 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2807 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2808 | }; |
| 2809 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2810 | // An incorrect reconnect would cause this to be read. |
| 2811 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2812 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2813 | }; |
| 2814 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2815 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2816 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2817 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2818 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2820 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2822 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2823 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2825 | |
| 2826 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2829 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2830 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2831 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2833 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2835 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2837 | |
| 2838 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2839 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2841 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2842 | ASSERT_TRUE(response); |
| 2843 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2844 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2848 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2849 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2850 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2852 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2853 | request.traffic_annotation = |
| 2854 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2855 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2857 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2858 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2859 | MockWrite("GET / HTTP/1.1\r\n" |
| 2860 | "Host: www.example.org\r\n" |
| 2861 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2862 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2863 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2864 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2865 | MockWrite("GET / HTTP/1.1\r\n" |
| 2866 | "Host: www.example.org\r\n" |
| 2867 | "Connection: keep-alive\r\n" |
| 2868 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2869 | }; |
| 2870 | |
| 2871 | // Respond with 5 kb of response body. |
| 2872 | std::string large_body_string("Unauthorized"); |
| 2873 | large_body_string.append(5 * 1024, ' '); |
| 2874 | large_body_string.append("\r\n"); |
| 2875 | |
| 2876 | MockRead data_reads1[] = { |
| 2877 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2878 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2879 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2880 | // 5134 = 12 + 5 * 1024 + 2 |
| 2881 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2882 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2883 | |
| 2884 | // Lastly, the server responds with the actual content. |
| 2885 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2886 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2887 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2888 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2889 | }; |
| 2890 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2891 | // An incorrect reconnect would cause this to be read. |
| 2892 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2893 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2894 | }; |
| 2895 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2896 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2897 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2899 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2901 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2904 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2906 | |
| 2907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2908 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2911 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2912 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2914 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2916 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2918 | |
| 2919 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2922 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2923 | ASSERT_TRUE(response); |
| 2924 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2925 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2929 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2930 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2931 | HttpRequestInfo request; |
| 2932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2933 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 2934 | request.traffic_annotation = |
| 2935 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2938 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2939 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2940 | MockWrite( |
| 2941 | "GET / HTTP/1.1\r\n" |
| 2942 | "Host: www.example.org\r\n" |
| 2943 | "Connection: keep-alive\r\n\r\n"), |
| 2944 | // This simulates the seemingly successful write to a closed connection |
| 2945 | // if the bug is not fixed. |
| 2946 | MockWrite( |
| 2947 | "GET / HTTP/1.1\r\n" |
| 2948 | "Host: www.example.org\r\n" |
| 2949 | "Connection: keep-alive\r\n" |
| 2950 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2951 | }; |
| 2952 | |
| 2953 | MockRead data_reads1[] = { |
| 2954 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2955 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2957 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2958 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2959 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2960 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2961 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2962 | }; |
| 2963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2964 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2965 | // be issuing -- the final header line contains the credentials. |
| 2966 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2967 | MockWrite( |
| 2968 | "GET / HTTP/1.1\r\n" |
| 2969 | "Host: www.example.org\r\n" |
| 2970 | "Connection: keep-alive\r\n" |
| 2971 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2972 | }; |
| 2973 | |
| 2974 | // Lastly, the server responds with the actual content. |
| 2975 | MockRead data_reads2[] = { |
| 2976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2977 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2978 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2979 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2980 | }; |
| 2981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2982 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2983 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2984 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2985 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2986 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2987 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2990 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2992 | |
| 2993 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2994 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2997 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2998 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3000 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3002 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3004 | |
| 3005 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3008 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3009 | ASSERT_TRUE(response); |
| 3010 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3011 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3012 | } |
| 3013 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3014 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3015 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3016 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3017 | HttpRequestInfo request; |
| 3018 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3019 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3020 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3021 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3022 | request.traffic_annotation = |
| 3023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3024 | |
| 3025 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3026 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3027 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3028 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3029 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3030 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3032 | |
| 3033 | // Since we have proxy, should try to establish tunnel. |
| 3034 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3035 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3036 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3037 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3038 | }; |
| 3039 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3040 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3041 | // connection. |
| 3042 | MockRead data_reads1[] = { |
| 3043 | // No credentials. |
| 3044 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3045 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3046 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3047 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3048 | // Since the first connection couldn't be reused, need to establish another |
| 3049 | // once given credentials. |
| 3050 | MockWrite data_writes2[] = { |
| 3051 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3052 | // be issuing -- the final header line contains the credentials. |
| 3053 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3054 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3055 | "Proxy-Connection: keep-alive\r\n" |
| 3056 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3057 | |
| 3058 | MockWrite("GET / HTTP/1.1\r\n" |
| 3059 | "Host: www.example.org\r\n" |
| 3060 | "Connection: keep-alive\r\n\r\n"), |
| 3061 | }; |
| 3062 | |
| 3063 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3064 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3065 | |
| 3066 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3067 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3069 | MockRead(SYNCHRONOUS, "hello"), |
| 3070 | }; |
| 3071 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3072 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3074 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3075 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3076 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3078 | |
| 3079 | TestCompletionCallback callback1; |
| 3080 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3081 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3082 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3083 | |
| 3084 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3086 | |
| 3087 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3088 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3089 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3090 | log.GetEntries(&entries); |
| 3091 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3092 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3093 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3094 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3095 | entries, pos, |
| 3096 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3097 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | |
| 3099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3100 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3101 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3102 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3103 | EXPECT_EQ(407, response->headers->response_code()); |
| 3104 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3105 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3106 | |
| 3107 | LoadTimingInfo load_timing_info; |
| 3108 | // CONNECT requests and responses are handled at the connect job level, so |
| 3109 | // the transaction does not yet have a connection. |
| 3110 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3111 | |
| 3112 | TestCompletionCallback callback2; |
| 3113 | |
| 3114 | rv = |
| 3115 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3117 | |
| 3118 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3119 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3120 | |
| 3121 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3122 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3123 | |
| 3124 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3125 | EXPECT_EQ(200, response->headers->response_code()); |
| 3126 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3127 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3128 | |
| 3129 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3130 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3131 | |
| 3132 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3133 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3134 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3135 | |
| 3136 | trans.reset(); |
| 3137 | session->CloseAllConnections(); |
| 3138 | } |
| 3139 | |
| 3140 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3141 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3142 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3143 | HttpRequestInfo request; |
| 3144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3145 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3146 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3147 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3148 | request.traffic_annotation = |
| 3149 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3150 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3151 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3152 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3153 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3154 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3155 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3156 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3157 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3158 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3159 | // Since we have proxy, should try to establish tunnel. |
| 3160 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3161 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3162 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3163 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3164 | }; |
| 3165 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3166 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3167 | // connection. |
| 3168 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3169 | // No credentials. |
| 3170 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3171 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3172 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3173 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3174 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3175 | MockWrite data_writes2[] = { |
| 3176 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3177 | // be issuing -- the final header line contains the credentials. |
| 3178 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3179 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3180 | "Proxy-Connection: keep-alive\r\n" |
| 3181 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3182 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3183 | MockWrite("GET / HTTP/1.1\r\n" |
| 3184 | "Host: www.example.org\r\n" |
| 3185 | "Connection: keep-alive\r\n\r\n"), |
| 3186 | }; |
| 3187 | |
| 3188 | MockRead data_reads2[] = { |
| 3189 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3190 | |
| 3191 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3192 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3193 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3194 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3195 | }; |
| 3196 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3197 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3199 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3200 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3201 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3203 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3204 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3205 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3206 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3207 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3209 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3211 | |
| 3212 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3213 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3214 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3215 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3216 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3217 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3218 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3219 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3220 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3221 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3222 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3223 | |
| 3224 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3225 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3226 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3227 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3228 | EXPECT_EQ(407, response->headers->response_code()); |
| 3229 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3230 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3231 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3232 | LoadTimingInfo load_timing_info; |
| 3233 | // CONNECT requests and responses are handled at the connect job level, so |
| 3234 | // the transaction does not yet have a connection. |
| 3235 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3237 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3239 | rv = trans->RestartWithAuth( |
| 3240 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3242 | |
| 3243 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3245 | |
| 3246 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3247 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3248 | |
| 3249 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3250 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3251 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3252 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3253 | |
| 3254 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3255 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3256 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3257 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3258 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3259 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3260 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3261 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3262 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3263 | } |
| 3264 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3265 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3266 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3267 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3268 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3269 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3270 | // reused. See http://crbug.com/544255. |
| 3271 | for (int i = 0; i < 2; ++i) { |
| 3272 | HttpRequestInfo request; |
| 3273 | request.method = "GET"; |
| 3274 | request.url = GURL("https://www.example.org/"); |
| 3275 | // Ensure that proxy authentication is attempted even |
| 3276 | // when the no authentication data flag is set. |
| 3277 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3278 | request.traffic_annotation = |
| 3279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3281 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3282 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3283 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3284 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3285 | BoundTestNetLog log; |
| 3286 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3288 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3290 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3291 | // Since we have proxy, should try to establish tunnel. |
| 3292 | MockWrite data_writes1[] = { |
| 3293 | MockWrite(ASYNC, 0, |
| 3294 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3295 | "Host: www.example.org:443\r\n" |
| 3296 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3298 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3299 | // be issuing -- the final header line contains the credentials. |
| 3300 | MockWrite(ASYNC, 3, |
| 3301 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3302 | "Host: www.example.org:443\r\n" |
| 3303 | "Proxy-Connection: keep-alive\r\n" |
| 3304 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3305 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3306 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3307 | // The proxy responds to the connect with a 407, using a persistent |
| 3308 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3309 | MockRead data_reads1[] = { |
| 3310 | // No credentials. |
| 3311 | MockRead(ASYNC, 1, |
| 3312 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3313 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3314 | "Proxy-Connection: keep-alive\r\n" |
| 3315 | "Content-Length: 10\r\n\r\n"), |
| 3316 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3317 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3318 | // Wrong credentials (wrong password). |
| 3319 | MockRead(ASYNC, 4, |
| 3320 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3321 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3322 | "Proxy-Connection: keep-alive\r\n" |
| 3323 | "Content-Length: 10\r\n\r\n"), |
| 3324 | // No response body because the test stops reading here. |
| 3325 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3326 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3327 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3328 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | data1.set_busy_before_sync_reads(true); |
| 3330 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3331 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3334 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3335 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3336 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3337 | TestNetLogEntry::List entries; |
| 3338 | log.GetEntries(&entries); |
| 3339 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3340 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3341 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3342 | ExpectLogContainsSomewhere( |
| 3343 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3344 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3345 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3347 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3348 | ASSERT_TRUE(response); |
| 3349 | ASSERT_TRUE(response->headers); |
| 3350 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3351 | EXPECT_EQ(407, response->headers->response_code()); |
| 3352 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3353 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3354 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3355 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3356 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3357 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3358 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3359 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3360 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3361 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3363 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3364 | ASSERT_TRUE(response); |
| 3365 | ASSERT_TRUE(response->headers); |
| 3366 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3367 | EXPECT_EQ(407, response->headers->response_code()); |
| 3368 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3369 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3370 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3371 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3372 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3373 | // out of scope. |
| 3374 | session->CloseAllConnections(); |
| 3375 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | } |
| 3377 | |
| 3378 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3379 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3380 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3381 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3382 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3383 | // reused. See http://crbug.com/544255. |
| 3384 | for (int i = 0; i < 2; ++i) { |
| 3385 | HttpRequestInfo request; |
| 3386 | request.method = "GET"; |
| 3387 | request.url = GURL("https://www.example.org/"); |
| 3388 | // Ensure that proxy authentication is attempted even |
| 3389 | // when the no authentication data flag is set. |
| 3390 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3391 | request.traffic_annotation = |
| 3392 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3393 | |
| 3394 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3395 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3396 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3397 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3398 | BoundTestNetLog log; |
| 3399 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3403 | |
| 3404 | // Since we have proxy, should try to establish tunnel. |
| 3405 | MockWrite data_writes1[] = { |
| 3406 | MockWrite(ASYNC, 0, |
| 3407 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3408 | "Host: www.example.org:443\r\n" |
| 3409 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3411 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3412 | // be issuing -- the final header line contains the credentials. |
| 3413 | MockWrite(ASYNC, 3, |
| 3414 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3415 | "Host: www.example.org:443\r\n" |
| 3416 | "Proxy-Connection: keep-alive\r\n" |
| 3417 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3418 | }; |
| 3419 | |
| 3420 | // The proxy responds to the connect with a 407, using a persistent |
| 3421 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3422 | MockRead data_reads1[] = { |
| 3423 | // No credentials. |
| 3424 | MockRead(ASYNC, 1, |
| 3425 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3426 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3427 | "Content-Length: 10\r\n\r\n"), |
| 3428 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3429 | |
| 3430 | // Wrong credentials (wrong password). |
| 3431 | MockRead(ASYNC, 4, |
| 3432 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3433 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3434 | "Content-Length: 10\r\n\r\n"), |
| 3435 | // No response body because the test stops reading here. |
| 3436 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3437 | }; |
| 3438 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3439 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3440 | data1.set_busy_before_sync_reads(true); |
| 3441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3442 | |
| 3443 | TestCompletionCallback callback1; |
| 3444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3445 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3446 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3447 | |
| 3448 | TestNetLogEntry::List entries; |
| 3449 | log.GetEntries(&entries); |
| 3450 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3451 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3452 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3453 | ExpectLogContainsSomewhere( |
| 3454 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3455 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3456 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3459 | ASSERT_TRUE(response); |
| 3460 | ASSERT_TRUE(response->headers); |
| 3461 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3462 | EXPECT_EQ(407, response->headers->response_code()); |
| 3463 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3464 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3465 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3466 | |
| 3467 | TestCompletionCallback callback2; |
| 3468 | |
| 3469 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3470 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3471 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3472 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3474 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3475 | ASSERT_TRUE(response); |
| 3476 | ASSERT_TRUE(response->headers); |
| 3477 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3478 | EXPECT_EQ(407, response->headers->response_code()); |
| 3479 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3480 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3481 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3482 | |
| 3483 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3484 | // out of scope. |
| 3485 | session->CloseAllConnections(); |
| 3486 | } |
| 3487 | } |
| 3488 | |
| 3489 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3490 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3491 | // the case the server sends extra data on the original socket, so it can't be |
| 3492 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3493 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3494 | HttpRequestInfo request; |
| 3495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3496 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3497 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3498 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3499 | request.traffic_annotation = |
| 3500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3501 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3502 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3503 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3504 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3505 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3506 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3507 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3509 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3510 | // Since we have proxy, should try to establish tunnel. |
| 3511 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3512 | MockWrite(ASYNC, 0, |
| 3513 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3514 | "Host: www.example.org:443\r\n" |
| 3515 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3516 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3517 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3518 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3519 | // extra data, so the socket cannot be reused. |
| 3520 | MockRead data_reads1[] = { |
| 3521 | // No credentials. |
| 3522 | MockRead(ASYNC, 1, |
| 3523 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3524 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3525 | "Content-Length: 10\r\n\r\n"), |
| 3526 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3527 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3528 | }; |
| 3529 | |
| 3530 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3531 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3532 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3533 | MockWrite(ASYNC, 0, |
| 3534 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3535 | "Host: www.example.org:443\r\n" |
| 3536 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3538 | |
| 3539 | MockWrite(ASYNC, 2, |
| 3540 | "GET / HTTP/1.1\r\n" |
| 3541 | "Host: www.example.org\r\n" |
| 3542 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3543 | }; |
| 3544 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3545 | MockRead data_reads2[] = { |
| 3546 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3547 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3548 | MockRead(ASYNC, 3, |
| 3549 | "HTTP/1.1 200 OK\r\n" |
| 3550 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3551 | "Content-Length: 5\r\n\r\n"), |
| 3552 | // No response body because the test stops reading here. |
| 3553 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3554 | }; |
| 3555 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3556 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3558 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3559 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3560 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3561 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3564 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3565 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3566 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3567 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3568 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3569 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3570 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3571 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3572 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3573 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3574 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3575 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3576 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3577 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3578 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3579 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3580 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3581 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3582 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3583 | ASSERT_TRUE(response); |
| 3584 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3585 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3586 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3587 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3588 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | LoadTimingInfo load_timing_info; |
| 3591 | // CONNECT requests and responses are handled at the connect job level, so |
| 3592 | // the transaction does not yet have a connection. |
| 3593 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3594 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3595 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3596 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3597 | rv = |
| 3598 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3599 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3600 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3601 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3602 | EXPECT_EQ(200, response->headers->response_code()); |
| 3603 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3604 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3605 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3606 | // The password prompt info should not be set. |
| 3607 | EXPECT_FALSE(response->auth_challenge); |
| 3608 | |
| 3609 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3610 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3611 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3612 | |
| 3613 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3614 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3615 | } |
| 3616 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3617 | // Test the case a proxy closes a socket while the challenge body is being |
| 3618 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3619 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3620 | HttpRequestInfo request; |
| 3621 | request.method = "GET"; |
| 3622 | request.url = GURL("https://www.example.org/"); |
| 3623 | // Ensure that proxy authentication is attempted even |
| 3624 | // when the no authentication data flag is set. |
| 3625 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3626 | request.traffic_annotation = |
| 3627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3628 | |
| 3629 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3630 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3631 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3632 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3635 | |
| 3636 | // Since we have proxy, should try to establish tunnel. |
| 3637 | MockWrite data_writes1[] = { |
| 3638 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3639 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3640 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3641 | }; |
| 3642 | |
| 3643 | // The proxy responds to the connect with a 407, using a persistent |
| 3644 | // connection. |
| 3645 | MockRead data_reads1[] = { |
| 3646 | // No credentials. |
| 3647 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3648 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3649 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3650 | // Server hands up in the middle of the body. |
| 3651 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3652 | }; |
| 3653 | |
| 3654 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3655 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3656 | // be issuing -- the final header line contains the credentials. |
| 3657 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3658 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3659 | "Proxy-Connection: keep-alive\r\n" |
| 3660 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3661 | |
| 3662 | MockWrite("GET / HTTP/1.1\r\n" |
| 3663 | "Host: www.example.org\r\n" |
| 3664 | "Connection: keep-alive\r\n\r\n"), |
| 3665 | }; |
| 3666 | |
| 3667 | MockRead data_reads2[] = { |
| 3668 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3669 | |
| 3670 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3671 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3672 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3673 | MockRead(SYNCHRONOUS, "hello"), |
| 3674 | }; |
| 3675 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3676 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3677 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3678 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3679 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3680 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3682 | |
| 3683 | TestCompletionCallback callback; |
| 3684 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3685 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3686 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3689 | ASSERT_TRUE(response); |
| 3690 | ASSERT_TRUE(response->headers); |
| 3691 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3692 | EXPECT_EQ(407, response->headers->response_code()); |
| 3693 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3695 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3696 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3699 | ASSERT_TRUE(response); |
| 3700 | ASSERT_TRUE(response->headers); |
| 3701 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3702 | EXPECT_EQ(200, response->headers->response_code()); |
| 3703 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3704 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3705 | EXPECT_EQ("hello", body); |
| 3706 | } |
| 3707 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3708 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3709 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3710 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3711 | HttpRequestInfo request; |
| 3712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3713 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3714 | request.traffic_annotation = |
| 3715 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3716 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3717 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3718 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3719 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3720 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3723 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3724 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3725 | // Since we have proxy, should try to establish tunnel. |
| 3726 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3727 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3728 | "Host: www.example.org:443\r\n" |
| 3729 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3730 | }; |
| 3731 | |
| 3732 | // The proxy responds to the connect with a 407. |
| 3733 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3734 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3735 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3736 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3737 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3738 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3739 | }; |
| 3740 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3741 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3744 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3748 | |
| 3749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3752 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3753 | ASSERT_TRUE(response); |
| 3754 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3755 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3756 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3757 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3758 | |
| 3759 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3760 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3761 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3762 | |
| 3763 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3764 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3765 | } |
| 3766 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3767 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3768 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3769 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3770 | HttpRequestInfo request; |
| 3771 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3772 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3773 | request.traffic_annotation = |
| 3774 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3775 | |
| 3776 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3777 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3778 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3783 | |
| 3784 | // Since we have proxy, should try to establish tunnel. |
| 3785 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3786 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3787 | "Host: www.example.org:443\r\n" |
| 3788 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3789 | }; |
| 3790 | |
| 3791 | // The proxy responds to the connect with a 407. |
| 3792 | MockRead data_reads[] = { |
| 3793 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3794 | MockRead("X-Foo: bar\r\n"), |
| 3795 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3796 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3797 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3798 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3799 | }; |
| 3800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3801 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3802 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3803 | |
| 3804 | TestCompletionCallback callback; |
| 3805 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3806 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3808 | |
| 3809 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3810 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3811 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3812 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3813 | ASSERT_TRUE(response); |
| 3814 | ASSERT_TRUE(response->headers); |
| 3815 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3816 | EXPECT_EQ(407, response->headers->response_code()); |
| 3817 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3818 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3819 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3820 | |
| 3821 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3822 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3823 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3824 | |
| 3825 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3826 | session->CloseAllConnections(); |
| 3827 | } |
| 3828 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3829 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3830 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3831 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3832 | HttpRequestInfo request; |
| 3833 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3834 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3835 | request.traffic_annotation = |
| 3836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3837 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3838 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3840 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3841 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3842 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3843 | MockWrite( |
| 3844 | "GET / HTTP/1.1\r\n" |
| 3845 | "Host: www.example.org\r\n" |
| 3846 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3847 | }; |
| 3848 | |
| 3849 | MockRead data_reads1[] = { |
| 3850 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3851 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3852 | // Large content-length -- won't matter, as connection will be reset. |
| 3853 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3854 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3855 | }; |
| 3856 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3857 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3858 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3859 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3860 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3862 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3864 | |
| 3865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3866 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3867 | } |
| 3868 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3869 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3870 | // through a non-authenticating proxy. The request should fail with |
| 3871 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3872 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3873 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3874 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3875 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3876 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3877 | HttpRequestInfo request; |
| 3878 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3879 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3880 | request.traffic_annotation = |
| 3881 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3882 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3883 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3884 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3885 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3886 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3888 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3889 | // Since we have proxy, should try to establish tunnel. |
| 3890 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3891 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3892 | "Host: www.example.org:443\r\n" |
| 3893 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3894 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3895 | MockWrite("GET / HTTP/1.1\r\n" |
| 3896 | "Host: www.example.org\r\n" |
| 3897 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3898 | }; |
| 3899 | |
| 3900 | MockRead data_reads1[] = { |
| 3901 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3902 | |
| 3903 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3904 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3905 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3906 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3907 | }; |
| 3908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3909 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3910 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3911 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3912 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3914 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3918 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3920 | |
| 3921 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3922 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3923 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3924 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3925 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3926 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3927 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3928 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3929 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3930 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3931 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3932 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3933 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3934 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3935 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3936 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3937 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3938 | HttpRequestInfo request; |
| 3939 | request.method = "GET"; |
| 3940 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 3941 | request.traffic_annotation = |
| 3942 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3943 | |
| 3944 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3945 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3946 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3947 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3948 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3949 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3950 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3951 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3952 | mock_handler->set_allows_default_credentials(true); |
| 3953 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3954 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3955 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3956 | |
| 3957 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3958 | NetLog net_log; |
| 3959 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3960 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3961 | |
| 3962 | // Since we have proxy, should try to establish tunnel. |
| 3963 | MockWrite data_writes1[] = { |
| 3964 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3965 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3966 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3967 | }; |
| 3968 | |
| 3969 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3970 | // connection. |
| 3971 | MockRead data_reads1[] = { |
| 3972 | // No credentials. |
| 3973 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3974 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3975 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3976 | }; |
| 3977 | |
| 3978 | // Since the first connection couldn't be reused, need to establish another |
| 3979 | // once given credentials. |
| 3980 | MockWrite data_writes2[] = { |
| 3981 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3982 | // be issuing -- the final header line contains the credentials. |
| 3983 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3984 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3985 | "Proxy-Connection: keep-alive\r\n" |
| 3986 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3987 | |
| 3988 | MockWrite("GET / HTTP/1.1\r\n" |
| 3989 | "Host: www.example.org\r\n" |
| 3990 | "Connection: keep-alive\r\n\r\n"), |
| 3991 | }; |
| 3992 | |
| 3993 | MockRead data_reads2[] = { |
| 3994 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3995 | |
| 3996 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3997 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3998 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3999 | MockRead(SYNCHRONOUS, "hello"), |
| 4000 | }; |
| 4001 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4002 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4003 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4004 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4005 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4006 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4007 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4008 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4009 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4010 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4011 | |
| 4012 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4013 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4014 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4015 | |
| 4016 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4017 | ASSERT_TRUE(response); |
| 4018 | ASSERT_TRUE(response->headers); |
| 4019 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4020 | EXPECT_EQ(407, response->headers->response_code()); |
| 4021 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4022 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4023 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4024 | |
| 4025 | LoadTimingInfo load_timing_info; |
| 4026 | // CONNECT requests and responses are handled at the connect job level, so |
| 4027 | // the transaction does not yet have a connection. |
| 4028 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4029 | |
| 4030 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4031 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4032 | response = trans->GetResponseInfo(); |
| 4033 | ASSERT_TRUE(response); |
| 4034 | ASSERT_TRUE(response->headers); |
| 4035 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4036 | EXPECT_EQ(200, response->headers->response_code()); |
| 4037 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4038 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4039 | |
| 4040 | // The password prompt info should not be set. |
| 4041 | EXPECT_FALSE(response->auth_challenge); |
| 4042 | |
| 4043 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4044 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4045 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4046 | |
| 4047 | trans.reset(); |
| 4048 | session->CloseAllConnections(); |
| 4049 | } |
| 4050 | |
| 4051 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4052 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4053 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4054 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4055 | HttpRequestInfo request; |
| 4056 | request.method = "GET"; |
| 4057 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4058 | request.traffic_annotation = |
| 4059 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4060 | |
| 4061 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4062 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4063 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4064 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4065 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4066 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4067 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4068 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4069 | mock_handler->set_allows_default_credentials(true); |
| 4070 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4071 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4072 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4073 | |
| 4074 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4075 | NetLog net_log; |
| 4076 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4077 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4078 | |
| 4079 | // Should try to establish tunnel. |
| 4080 | MockWrite data_writes1[] = { |
| 4081 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4082 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4083 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4084 | |
| 4085 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4086 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4087 | "Proxy-Connection: keep-alive\r\n" |
| 4088 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4089 | }; |
| 4090 | |
| 4091 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4092 | // connection. |
| 4093 | MockRead data_reads1[] = { |
| 4094 | // No credentials. |
| 4095 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4096 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4097 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4098 | }; |
| 4099 | |
| 4100 | // Since the first connection was closed, need to establish another once given |
| 4101 | // credentials. |
| 4102 | MockWrite data_writes2[] = { |
| 4103 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4104 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4105 | "Proxy-Connection: keep-alive\r\n" |
| 4106 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4107 | |
| 4108 | MockWrite("GET / HTTP/1.1\r\n" |
| 4109 | "Host: www.example.org\r\n" |
| 4110 | "Connection: keep-alive\r\n\r\n"), |
| 4111 | }; |
| 4112 | |
| 4113 | MockRead data_reads2[] = { |
| 4114 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4115 | |
| 4116 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4117 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4118 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4119 | MockRead(SYNCHRONOUS, "hello"), |
| 4120 | }; |
| 4121 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4122 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4124 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4125 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4126 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4128 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4129 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4130 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4131 | |
| 4132 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4133 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4134 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4135 | |
| 4136 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4137 | ASSERT_TRUE(response); |
| 4138 | ASSERT_TRUE(response->headers); |
| 4139 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4140 | EXPECT_EQ(407, response->headers->response_code()); |
| 4141 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4142 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4143 | EXPECT_FALSE(response->auth_challenge); |
| 4144 | |
| 4145 | LoadTimingInfo load_timing_info; |
| 4146 | // CONNECT requests and responses are handled at the connect job level, so |
| 4147 | // the transaction does not yet have a connection. |
| 4148 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4149 | |
| 4150 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4151 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4152 | |
| 4153 | response = trans->GetResponseInfo(); |
| 4154 | ASSERT_TRUE(response); |
| 4155 | ASSERT_TRUE(response->headers); |
| 4156 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4157 | EXPECT_EQ(200, response->headers->response_code()); |
| 4158 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4159 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4160 | |
| 4161 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4162 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4163 | |
| 4164 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4165 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4166 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4167 | |
| 4168 | trans.reset(); |
| 4169 | session->CloseAllConnections(); |
| 4170 | } |
| 4171 | |
| 4172 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4173 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4174 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4175 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4176 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4177 | HttpRequestInfo request; |
| 4178 | request.method = "GET"; |
| 4179 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4180 | request.traffic_annotation = |
| 4181 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | |
| 4183 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4184 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4185 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4186 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4188 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4190 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4191 | mock_handler->set_allows_default_credentials(true); |
| 4192 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4193 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4194 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4195 | |
| 4196 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4197 | NetLog net_log; |
| 4198 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4199 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4200 | |
| 4201 | // Should try to establish tunnel. |
| 4202 | MockWrite data_writes1[] = { |
| 4203 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4204 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4206 | |
| 4207 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4208 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | "Proxy-Connection: keep-alive\r\n" |
| 4210 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4211 | }; |
| 4212 | |
| 4213 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4214 | // second request is sent. |
| 4215 | MockRead data_reads1[] = { |
| 4216 | // No credentials. |
| 4217 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4218 | MockRead("Content-Length: 0\r\n"), |
| 4219 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4220 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4221 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4222 | }; |
| 4223 | |
| 4224 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4225 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4226 | // request. |
| 4227 | MockWrite data_writes2[] = { |
| 4228 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4229 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4230 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4231 | }; |
| 4232 | |
| 4233 | // The proxy, having had more than enough of us, just hangs up. |
| 4234 | MockRead data_reads2[] = { |
| 4235 | // No credentials. |
| 4236 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4237 | }; |
| 4238 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4239 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4241 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4242 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4243 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4244 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4245 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4246 | |
| 4247 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4248 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4249 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4250 | |
| 4251 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4252 | ASSERT_TRUE(response); |
| 4253 | ASSERT_TRUE(response->headers); |
| 4254 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4255 | EXPECT_EQ(407, response->headers->response_code()); |
| 4256 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4257 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4258 | EXPECT_FALSE(response->auth_challenge); |
| 4259 | |
| 4260 | LoadTimingInfo load_timing_info; |
| 4261 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4262 | |
| 4263 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4264 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4265 | |
| 4266 | trans.reset(); |
| 4267 | session->CloseAllConnections(); |
| 4268 | } |
| 4269 | |
| 4270 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4271 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4272 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4273 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4274 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4275 | HttpRequestInfo request; |
| 4276 | request.method = "GET"; |
| 4277 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4278 | request.traffic_annotation = |
| 4279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | |
| 4281 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4282 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4283 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4284 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4285 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4286 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4287 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4288 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4289 | mock_handler->set_allows_default_credentials(true); |
| 4290 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4291 | HttpAuth::AUTH_PROXY); |
| 4292 | // Add another handler for the second challenge. It supports default |
| 4293 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4294 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4295 | mock_handler->set_allows_default_credentials(true); |
| 4296 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4297 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4298 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4299 | |
| 4300 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4301 | NetLog net_log; |
| 4302 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4303 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4304 | |
| 4305 | // Should try to establish tunnel. |
| 4306 | MockWrite data_writes1[] = { |
| 4307 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4308 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4310 | }; |
| 4311 | |
| 4312 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4313 | // connection. |
| 4314 | MockRead data_reads1[] = { |
| 4315 | // No credentials. |
| 4316 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4317 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4318 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4319 | }; |
| 4320 | |
| 4321 | // Since the first connection was closed, need to establish another once given |
| 4322 | // credentials. |
| 4323 | MockWrite data_writes2[] = { |
| 4324 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4325 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4326 | "Proxy-Connection: keep-alive\r\n" |
| 4327 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4328 | }; |
| 4329 | |
| 4330 | MockRead data_reads2[] = { |
| 4331 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4332 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4333 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4334 | }; |
| 4335 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4336 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4337 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4338 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4339 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4340 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4342 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4343 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4345 | |
| 4346 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4347 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4348 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4349 | |
| 4350 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4351 | ASSERT_TRUE(response); |
| 4352 | ASSERT_TRUE(response->headers); |
| 4353 | EXPECT_EQ(407, response->headers->response_code()); |
| 4354 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4355 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4356 | EXPECT_FALSE(response->auth_challenge); |
| 4357 | |
| 4358 | LoadTimingInfo load_timing_info; |
| 4359 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4360 | |
| 4361 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4362 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4363 | response = trans->GetResponseInfo(); |
| 4364 | ASSERT_TRUE(response); |
| 4365 | ASSERT_TRUE(response->headers); |
| 4366 | EXPECT_EQ(407, response->headers->response_code()); |
| 4367 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4368 | EXPECT_TRUE(response->auth_challenge); |
| 4369 | |
| 4370 | trans.reset(); |
| 4371 | session->CloseAllConnections(); |
| 4372 | } |
| 4373 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4374 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4375 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4376 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4377 | // authentication handshake can continue with the same scheme but with a |
| 4378 | // different identity. |
| 4379 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4380 | HttpRequestInfo request; |
| 4381 | request.method = "GET"; |
| 4382 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4383 | request.traffic_annotation = |
| 4384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4385 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4386 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4387 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4388 | |
| 4389 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4390 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4391 | mock_handler->set_allows_default_credentials(true); |
| 4392 | mock_handler->set_allows_explicit_credentials(true); |
| 4393 | mock_handler->set_connection_based(true); |
| 4394 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4395 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4396 | HttpAuth::AUTH_SERVER); |
| 4397 | |
| 4398 | // Add another handler for the second challenge. It supports default |
| 4399 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4400 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4401 | mock_handler->set_allows_default_credentials(true); |
| 4402 | mock_handler->set_allows_explicit_credentials(true); |
| 4403 | mock_handler->set_connection_based(true); |
| 4404 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4405 | HttpAuth::AUTH_SERVER); |
| 4406 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4407 | |
| 4408 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4409 | |
| 4410 | MockWrite data_writes1[] = { |
| 4411 | MockWrite("GET / HTTP/1.1\r\n" |
| 4412 | "Host: www.example.org\r\n" |
| 4413 | "Connection: keep-alive\r\n\r\n"), |
| 4414 | }; |
| 4415 | |
| 4416 | MockRead data_reads1[] = { |
| 4417 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4418 | "WWW-Authenticate: Mock\r\n" |
| 4419 | "Connection: keep-alive\r\n\r\n"), |
| 4420 | }; |
| 4421 | |
| 4422 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4423 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4424 | // transaction procceds without an authorization header. |
| 4425 | MockWrite data_writes2[] = { |
| 4426 | MockWrite("GET / HTTP/1.1\r\n" |
| 4427 | "Host: www.example.org\r\n" |
| 4428 | "Connection: keep-alive\r\n\r\n"), |
| 4429 | }; |
| 4430 | |
| 4431 | MockRead data_reads2[] = { |
| 4432 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4433 | "WWW-Authenticate: Mock\r\n" |
| 4434 | "Connection: keep-alive\r\n\r\n"), |
| 4435 | }; |
| 4436 | |
| 4437 | MockWrite data_writes3[] = { |
| 4438 | MockWrite("GET / HTTP/1.1\r\n" |
| 4439 | "Host: www.example.org\r\n" |
| 4440 | "Connection: keep-alive\r\n" |
| 4441 | "Authorization: auth_token\r\n\r\n"), |
| 4442 | }; |
| 4443 | |
| 4444 | MockRead data_reads3[] = { |
| 4445 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4446 | "Content-Length: 5\r\n" |
| 4447 | "Content-Type: text/plain\r\n" |
| 4448 | "Connection: keep-alive\r\n\r\n" |
| 4449 | "Hello"), |
| 4450 | }; |
| 4451 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4452 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4453 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4454 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4455 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4456 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4457 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4458 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4459 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4460 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4461 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4462 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4463 | |
| 4464 | TestCompletionCallback callback; |
| 4465 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4466 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4467 | |
| 4468 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4469 | ASSERT_TRUE(response); |
| 4470 | ASSERT_TRUE(response->headers); |
| 4471 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4472 | |
| 4473 | // The following three tests assert that an authentication challenge was |
| 4474 | // received and that the stack is ready to respond to the challenge using |
| 4475 | // ambient credentials. |
| 4476 | EXPECT_EQ(401, response->headers->response_code()); |
| 4477 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4478 | EXPECT_FALSE(response->auth_challenge); |
| 4479 | |
| 4480 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4481 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4482 | response = trans->GetResponseInfo(); |
| 4483 | ASSERT_TRUE(response); |
| 4484 | ASSERT_TRUE(response->headers); |
| 4485 | |
| 4486 | // The following three tests assert that an authentication challenge was |
| 4487 | // received and that the stack needs explicit credentials before it is ready |
| 4488 | // to respond to the challenge. |
| 4489 | EXPECT_EQ(401, response->headers->response_code()); |
| 4490 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4491 | EXPECT_TRUE(response->auth_challenge); |
| 4492 | |
| 4493 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4494 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4495 | response = trans->GetResponseInfo(); |
| 4496 | ASSERT_TRUE(response); |
| 4497 | ASSERT_TRUE(response->headers); |
| 4498 | EXPECT_EQ(200, response->headers->response_code()); |
| 4499 | |
| 4500 | trans.reset(); |
| 4501 | session->CloseAllConnections(); |
| 4502 | } |
| 4503 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4504 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4505 | // schemes, based on the path of the URL being requests. |
| 4506 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4507 | public: |
| 4508 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4509 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4510 | |
| 4511 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4512 | |
| 4513 | static HostPortPair ProxyHostPortPair() { |
| 4514 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4515 | } |
| 4516 | |
| 4517 | // ProxyResolver implementation. |
| 4518 | int GetProxyForURL(const GURL& url, |
| 4519 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4520 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4521 | std::unique_ptr<Request>* request, |
| 4522 | const NetLogWithSource& /*net_log*/) override { |
| 4523 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4524 | results->set_traffic_annotation( |
| 4525 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4526 | if (url.path() == "/socks4") { |
| 4527 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4528 | return OK; |
| 4529 | } |
| 4530 | if (url.path() == "/socks5") { |
| 4531 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4532 | return OK; |
| 4533 | } |
| 4534 | if (url.path() == "/http") { |
| 4535 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4536 | return OK; |
| 4537 | } |
| 4538 | if (url.path() == "/https") { |
| 4539 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4540 | return OK; |
| 4541 | } |
| 4542 | NOTREACHED(); |
| 4543 | return ERR_NOT_IMPLEMENTED; |
| 4544 | } |
| 4545 | |
| 4546 | private: |
| 4547 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4548 | }; |
| 4549 | |
| 4550 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4551 | : public ProxyResolverFactory { |
| 4552 | public: |
| 4553 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4554 | : ProxyResolverFactory(false) {} |
| 4555 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4556 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4557 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4558 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4559 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4560 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4561 | return OK; |
| 4562 | } |
| 4563 | |
| 4564 | private: |
| 4565 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4566 | }; |
| 4567 | |
| 4568 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4569 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4570 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4571 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4572 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4573 | session_deps_.proxy_resolution_service = |
| 4574 | std::make_unique<ProxyResolutionService>( |
| 4575 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4576 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4577 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4578 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4579 | |
| 4580 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4581 | |
| 4582 | MockWrite socks_writes[] = { |
| 4583 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4584 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4585 | MockWrite(SYNCHRONOUS, |
| 4586 | "GET /socks4 HTTP/1.1\r\n" |
| 4587 | "Host: test\r\n" |
| 4588 | "Connection: keep-alive\r\n\r\n"), |
| 4589 | }; |
| 4590 | MockRead socks_reads[] = { |
| 4591 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4592 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4593 | "Connection: keep-alive\r\n" |
| 4594 | "Content-Length: 15\r\n\r\n" |
| 4595 | "SOCKS4 Response"), |
| 4596 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4597 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4598 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4599 | |
| 4600 | const char kSOCKS5Request[] = { |
| 4601 | 0x05, // Version |
| 4602 | 0x01, // Command (CONNECT) |
| 4603 | 0x00, // Reserved |
| 4604 | 0x03, // Address type (DOMAINNAME) |
| 4605 | 0x04, // Length of domain (4) |
| 4606 | 't', 'e', 's', 't', // Domain string |
| 4607 | 0x00, 0x50, // 16-bit port (80) |
| 4608 | }; |
| 4609 | MockWrite socks5_writes[] = { |
| 4610 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4611 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4612 | MockWrite(SYNCHRONOUS, |
| 4613 | "GET /socks5 HTTP/1.1\r\n" |
| 4614 | "Host: test\r\n" |
| 4615 | "Connection: keep-alive\r\n\r\n"), |
| 4616 | }; |
| 4617 | MockRead socks5_reads[] = { |
| 4618 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4619 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4620 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4621 | "Connection: keep-alive\r\n" |
| 4622 | "Content-Length: 15\r\n\r\n" |
| 4623 | "SOCKS5 Response"), |
| 4624 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4625 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4626 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4627 | |
| 4628 | MockWrite http_writes[] = { |
| 4629 | MockWrite(SYNCHRONOUS, |
| 4630 | "GET http://test/http HTTP/1.1\r\n" |
| 4631 | "Host: test\r\n" |
| 4632 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4633 | }; |
| 4634 | MockRead http_reads[] = { |
| 4635 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4636 | "Proxy-Connection: keep-alive\r\n" |
| 4637 | "Content-Length: 13\r\n\r\n" |
| 4638 | "HTTP Response"), |
| 4639 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4640 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4641 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4642 | |
| 4643 | MockWrite https_writes[] = { |
| 4644 | MockWrite(SYNCHRONOUS, |
| 4645 | "GET http://test/https HTTP/1.1\r\n" |
| 4646 | "Host: test\r\n" |
| 4647 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4648 | }; |
| 4649 | MockRead https_reads[] = { |
| 4650 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4651 | "Proxy-Connection: keep-alive\r\n" |
| 4652 | "Content-Length: 14\r\n\r\n" |
| 4653 | "HTTPS Response"), |
| 4654 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4655 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4656 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4657 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4659 | |
| 4660 | struct TestCase { |
| 4661 | GURL url; |
| 4662 | std::string expected_response; |
| 4663 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4664 | // after the test. |
| 4665 | int expected_idle_socks_sockets; |
| 4666 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4667 | // the test. |
| 4668 | int expected_idle_http_sockets; |
| 4669 | } const kTestCases[] = { |
| 4670 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4671 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4672 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4673 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4674 | }; |
| 4675 | |
| 4676 | for (const auto& test_case : kTestCases) { |
| 4677 | HttpRequestInfo request; |
| 4678 | request.method = "GET"; |
| 4679 | request.url = test_case.url; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4680 | request.traffic_annotation = |
| 4681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4682 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4683 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4684 | session.get()); |
| 4685 | TestCompletionCallback callback; |
| 4686 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4687 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4688 | |
| 4689 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4690 | ASSERT_TRUE(response); |
| 4691 | ASSERT_TRUE(response->headers); |
| 4692 | EXPECT_EQ(200, response->headers->response_code()); |
| 4693 | std::string response_data; |
| 4694 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4695 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4696 | |
| 4697 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4698 | // the next requests. |
| 4699 | trans.reset(); |
| 4700 | base::RunLoop().RunUntilIdle(); |
| 4701 | |
| 4702 | // Check the number of idle sockets in the pool, to make sure that used |
| 4703 | // sockets are indeed being returned to the socket pool. If each request |
| 4704 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4705 | // pass. |
| 4706 | EXPECT_EQ( |
| 4707 | test_case.expected_idle_socks_sockets, |
| 4708 | session |
| 4709 | ->GetSocketPoolForSOCKSProxy( |
| 4710 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4711 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4712 | ->IdleSocketCount()); |
| 4713 | EXPECT_EQ( |
| 4714 | test_case.expected_idle_http_sockets, |
| 4715 | session |
| 4716 | ->GetSocketPoolForHTTPProxy( |
| 4717 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4718 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4719 | ->IdleSocketCount()); |
| 4720 | } |
| 4721 | } |
| 4722 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4723 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4724 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4725 | HttpRequestInfo request1; |
| 4726 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4727 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4728 | request1.traffic_annotation = |
| 4729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4730 | |
| 4731 | HttpRequestInfo request2; |
| 4732 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4733 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4734 | request2.traffic_annotation = |
| 4735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4736 | |
| 4737 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4738 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4739 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4740 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4741 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4743 | |
| 4744 | // Since we have proxy, should try to establish tunnel. |
| 4745 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4746 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4747 | "Host: www.example.org:443\r\n" |
| 4748 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4749 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4750 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4751 | "Host: www.example.org\r\n" |
| 4752 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4753 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4754 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4755 | "Host: www.example.org\r\n" |
| 4756 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4757 | }; |
| 4758 | |
| 4759 | // The proxy responds to the connect with a 407, using a persistent |
| 4760 | // connection. |
| 4761 | MockRead data_reads1[] = { |
| 4762 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4763 | |
| 4764 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4765 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4766 | MockRead(SYNCHRONOUS, "1"), |
| 4767 | |
| 4768 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4769 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4770 | MockRead(SYNCHRONOUS, "22"), |
| 4771 | }; |
| 4772 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4773 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4774 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4775 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4777 | |
| 4778 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4779 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4780 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4781 | |
| 4782 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4784 | |
| 4785 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4786 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4787 | |
| 4788 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4789 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4790 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4791 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4792 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4793 | |
| 4794 | LoadTimingInfo load_timing_info1; |
| 4795 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4796 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4797 | |
| 4798 | trans1.reset(); |
| 4799 | |
| 4800 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4801 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4802 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4803 | |
| 4804 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4806 | |
| 4807 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4809 | |
| 4810 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4811 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4812 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4813 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4814 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4815 | |
| 4816 | LoadTimingInfo load_timing_info2; |
| 4817 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4818 | TestLoadTimingReused(load_timing_info2); |
| 4819 | |
| 4820 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4821 | |
| 4822 | trans2.reset(); |
| 4823 | session->CloseAllConnections(); |
| 4824 | } |
| 4825 | |
| 4826 | // 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] | 4827 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4828 | HttpRequestInfo request1; |
| 4829 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4830 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4831 | request1.traffic_annotation = |
| 4832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4833 | |
| 4834 | HttpRequestInfo request2; |
| 4835 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4836 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4837 | request2.traffic_annotation = |
| 4838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4839 | |
| 4840 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4841 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4842 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4843 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4844 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4845 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4847 | |
| 4848 | // Since we have proxy, should try to establish tunnel. |
| 4849 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4850 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4851 | "Host: www.example.org:443\r\n" |
| 4852 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4853 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4854 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4855 | "Host: www.example.org\r\n" |
| 4856 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4857 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4858 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4859 | "Host: www.example.org\r\n" |
| 4860 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4861 | }; |
| 4862 | |
| 4863 | // The proxy responds to the connect with a 407, using a persistent |
| 4864 | // connection. |
| 4865 | MockRead data_reads1[] = { |
| 4866 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4867 | |
| 4868 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4869 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4870 | MockRead(SYNCHRONOUS, "1"), |
| 4871 | |
| 4872 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4873 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4874 | MockRead(SYNCHRONOUS, "22"), |
| 4875 | }; |
| 4876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4877 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4879 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4880 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4881 | |
| 4882 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4883 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4884 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4885 | |
| 4886 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4888 | |
| 4889 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4890 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4891 | |
| 4892 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4893 | ASSERT_TRUE(response1); |
| 4894 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4895 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4896 | |
| 4897 | LoadTimingInfo load_timing_info1; |
| 4898 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4899 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4900 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4901 | |
| 4902 | trans1.reset(); |
| 4903 | |
| 4904 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4905 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4906 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4907 | |
| 4908 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4910 | |
| 4911 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4912 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4913 | |
| 4914 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4915 | ASSERT_TRUE(response2); |
| 4916 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4917 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4918 | |
| 4919 | LoadTimingInfo load_timing_info2; |
| 4920 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4921 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4922 | |
| 4923 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4924 | |
| 4925 | trans2.reset(); |
| 4926 | session->CloseAllConnections(); |
| 4927 | } |
| 4928 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4929 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4930 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4931 | HttpRequestInfo request; |
| 4932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4933 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4934 | request.traffic_annotation = |
| 4935 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4936 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4937 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4938 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4939 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4940 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4941 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4943 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4944 | // Since we have proxy, should use full url |
| 4945 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4946 | MockWrite( |
| 4947 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4948 | "Host: www.example.org\r\n" |
| 4949 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4950 | }; |
| 4951 | |
| 4952 | MockRead data_reads1[] = { |
| 4953 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4954 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4955 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4956 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4957 | }; |
| 4958 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4959 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4960 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4961 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4964 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4968 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4970 | |
| 4971 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4973 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4974 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4975 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4976 | TestLoadTimingNotReused(load_timing_info, |
| 4977 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4979 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4980 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4981 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4982 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4983 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4984 | EXPECT_EQ(200, response->headers->response_code()); |
| 4985 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4986 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4987 | |
| 4988 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4989 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4990 | } |
| 4991 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4992 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4993 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4994 | HttpRequestInfo request; |
| 4995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4996 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 4997 | request.traffic_annotation = |
| 4998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4999 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5000 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5001 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5002 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5003 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5004 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5006 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5007 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5008 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5009 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5010 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5011 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5012 | spdy::SpdySerializedFrame resp( |
| 5013 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5014 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5015 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5016 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5017 | }; |
| 5018 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5019 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5020 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5021 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5022 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5023 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5024 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5025 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5026 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5028 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5030 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5032 | |
| 5033 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5034 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5035 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5036 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5037 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5038 | TestLoadTimingNotReused(load_timing_info, |
| 5039 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5041 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5042 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5043 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5044 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5045 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5046 | |
| 5047 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5048 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5049 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5050 | } |
| 5051 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5052 | // Verifies that a session which races and wins against the owning transaction |
| 5053 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5054 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5055 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5056 | HttpRequestInfo request; |
| 5057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5058 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5059 | request.traffic_annotation = |
| 5060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5061 | |
| 5062 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5063 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5064 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5065 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5066 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5068 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5069 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5070 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5071 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5072 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5073 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5074 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5075 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5076 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5077 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5078 | }; |
| 5079 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5080 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5081 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5082 | |
| 5083 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5084 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5086 | |
| 5087 | TestCompletionCallback callback1; |
| 5088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5090 | |
| 5091 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5092 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5094 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5096 | |
| 5097 | // Race a session to the proxy, which completes first. |
| 5098 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5099 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5100 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5101 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5102 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5103 | |
| 5104 | // Unstall the resolution begun by the transaction. |
| 5105 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5106 | session_deps_.host_resolver->ResolveAllPending(); |
| 5107 | |
| 5108 | EXPECT_FALSE(callback1.have_result()); |
| 5109 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5112 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5113 | ASSERT_TRUE(response); |
| 5114 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5115 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5116 | |
| 5117 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5118 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5119 | EXPECT_EQ(kUploadData, response_data); |
| 5120 | } |
| 5121 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5122 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5123 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5124 | HttpRequestInfo request; |
| 5125 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5126 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5127 | request.traffic_annotation = |
| 5128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5129 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5130 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5131 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5132 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5133 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5134 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5136 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5137 | // The first request will be a bare GET, the second request will be a |
| 5138 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5139 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5140 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5141 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5142 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5143 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5144 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5145 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5146 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5147 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5148 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5149 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5150 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5151 | }; |
| 5152 | |
| 5153 | // The first response is a 407 proxy authentication challenge, and the second |
| 5154 | // response will be a 200 response since the second request includes a valid |
| 5155 | // Authorization header. |
| 5156 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5157 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5158 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5159 | spdy::SpdySerializedFrame resp_authentication( |
| 5160 | spdy_util_.ConstructSpdyReplyError( |
| 5161 | "407", kExtraAuthenticationHeaders, |
| 5162 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5163 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5164 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5165 | spdy::SpdySerializedFrame resp_data( |
| 5166 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5167 | spdy::SpdySerializedFrame body_data( |
| 5168 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5169 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5170 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5171 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5172 | CreateMockRead(resp_data, 4), |
| 5173 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5174 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5175 | }; |
| 5176 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5177 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5179 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5180 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5181 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5184 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5188 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5190 | |
| 5191 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5192 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5194 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5195 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5196 | ASSERT_TRUE(response); |
| 5197 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5198 | EXPECT_EQ(407, response->headers->response_code()); |
| 5199 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5200 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5201 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5202 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5204 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5206 | |
| 5207 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5210 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5211 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5212 | ASSERT_TRUE(response_restart); |
| 5213 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5214 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5215 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5216 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5217 | } |
| 5218 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5219 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5220 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5221 | HttpRequestInfo request; |
| 5222 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5223 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5224 | request.traffic_annotation = |
| 5225 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5226 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5227 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5228 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5229 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5230 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5231 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5235 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5236 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5237 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5238 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5239 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5240 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5241 | const char get[] = |
| 5242 | "GET / HTTP/1.1\r\n" |
| 5243 | "Host: www.example.org\r\n" |
| 5244 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5245 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5246 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5247 | spdy::SpdySerializedFrame conn_resp( |
| 5248 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5249 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5250 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5251 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5252 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5253 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5254 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5255 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5256 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5257 | |
| 5258 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5259 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5260 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5261 | }; |
| 5262 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5263 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5264 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5265 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5266 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5267 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5268 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5269 | }; |
| 5270 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5271 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5272 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5273 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5274 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5275 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5277 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5278 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5279 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5280 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5282 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5284 | |
| 5285 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5286 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5287 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5288 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5289 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5290 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5292 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5293 | ASSERT_TRUE(response); |
| 5294 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5295 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5296 | |
| 5297 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5298 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5299 | EXPECT_EQ("1234567890", response_data); |
| 5300 | } |
| 5301 | |
| 5302 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5303 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5304 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5305 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5306 | HttpRequestInfo request; |
| 5307 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5308 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5309 | request.traffic_annotation = |
| 5310 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5311 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5312 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5313 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5314 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5315 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5316 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5318 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5319 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5320 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5321 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5322 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5323 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5324 | // fetch https://www.example.org/ via SPDY |
| 5325 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5326 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5327 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5328 | spdy::SpdySerializedFrame wrapped_get( |
| 5329 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5330 | spdy::SpdySerializedFrame conn_resp( |
| 5331 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5332 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5333 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5334 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5335 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5336 | spdy::SpdySerializedFrame body( |
| 5337 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5338 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5339 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5340 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5342 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5343 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5344 | |
| 5345 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5346 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5347 | CreateMockWrite(window_update_get_resp, 6), |
| 5348 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5349 | }; |
| 5350 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5351 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5352 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5353 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5354 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5355 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5356 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5357 | }; |
| 5358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5359 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5360 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5361 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5362 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5363 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5365 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5366 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5368 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5369 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5371 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5373 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5374 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5375 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5376 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5377 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5378 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5379 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5380 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5381 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5382 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5383 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5385 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5386 | ASSERT_TRUE(response); |
| 5387 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5388 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5389 | |
| 5390 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5391 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5392 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5393 | } |
| 5394 | |
| 5395 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5396 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5397 | HttpRequestInfo request; |
| 5398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5399 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5400 | request.traffic_annotation = |
| 5401 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5402 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5403 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5404 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5405 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5406 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5411 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5412 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5413 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5414 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5415 | spdy::SpdySerializedFrame get( |
| 5416 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5417 | |
| 5418 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5419 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5420 | }; |
| 5421 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5422 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5423 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5424 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5425 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5426 | }; |
| 5427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5428 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5429 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5430 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5431 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5432 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5434 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5435 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5437 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5438 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5440 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5441 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5442 | |
| 5443 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5444 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5445 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5446 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5447 | } |
| 5448 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5449 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5450 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5451 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5452 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5453 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5454 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5455 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5456 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5457 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5458 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5459 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5460 | |
| 5461 | HttpRequestInfo request1; |
| 5462 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5463 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5464 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5465 | request1.traffic_annotation = |
| 5466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5467 | |
| 5468 | HttpRequestInfo request2; |
| 5469 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5470 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5471 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5472 | request2.traffic_annotation = |
| 5473 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5474 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5475 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5476 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5477 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5478 | spdy::SpdySerializedFrame conn_resp1( |
| 5479 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5480 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5481 | // Fetch https://www.example.org/ via HTTP. |
| 5482 | const char get1[] = |
| 5483 | "GET / HTTP/1.1\r\n" |
| 5484 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5485 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5486 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5487 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5488 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5489 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5490 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5491 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5492 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5493 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5494 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5495 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5496 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5497 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5498 | spdy::SpdyHeaderBlock connect2_block; |
| 5499 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 5500 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 5501 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5502 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5503 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5504 | spdy::SpdySerializedFrame conn_resp2( |
| 5505 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5506 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5507 | // Fetch https://mail.example.org/ via HTTP. |
| 5508 | const char get2[] = |
| 5509 | "GET / HTTP/1.1\r\n" |
| 5510 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5511 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5512 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5513 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5514 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5515 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5516 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5517 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5518 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5519 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5520 | |
| 5521 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5522 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5523 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5524 | }; |
| 5525 | |
| 5526 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5527 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5528 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5529 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5530 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5531 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5532 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5533 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5534 | }; |
| 5535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5536 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5537 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5538 | |
| 5539 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5540 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5542 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5544 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5545 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5546 | |
| 5547 | TestCompletionCallback callback; |
| 5548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5549 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5550 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5551 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5552 | |
| 5553 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5554 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5555 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5558 | ASSERT_TRUE(response); |
| 5559 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5560 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5561 | |
| 5562 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5563 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5564 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5565 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5567 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5568 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5569 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5570 | |
| 5571 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5572 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5573 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5574 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5575 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5576 | |
| 5577 | // The requests should have different IDs, since they each are using their own |
| 5578 | // separate stream. |
| 5579 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5581 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5582 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5586 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5587 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5588 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5589 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5590 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5591 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5592 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5593 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5594 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5595 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5596 | |
| 5597 | HttpRequestInfo request1; |
| 5598 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5599 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5600 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5601 | request1.traffic_annotation = |
| 5602 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5603 | |
| 5604 | HttpRequestInfo request2; |
| 5605 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5606 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5607 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5608 | request2.traffic_annotation = |
| 5609 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5610 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5611 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5612 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5613 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5614 | spdy::SpdySerializedFrame conn_resp1( |
| 5615 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5616 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5617 | // Fetch https://www.example.org/ via HTTP. |
| 5618 | const char get1[] = |
| 5619 | "GET / HTTP/1.1\r\n" |
| 5620 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5621 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5622 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5623 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5624 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5625 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5626 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5627 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5628 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5629 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5630 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5631 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5632 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5633 | // Fetch https://www.example.org/2 via HTTP. |
| 5634 | const char get2[] = |
| 5635 | "GET /2 HTTP/1.1\r\n" |
| 5636 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5637 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5638 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5639 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5640 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5641 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5642 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5643 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5644 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5645 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5646 | |
| 5647 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5648 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5649 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5650 | }; |
| 5651 | |
| 5652 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5653 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5654 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5655 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5656 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5657 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5658 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5659 | }; |
| 5660 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5661 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5662 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5663 | |
| 5664 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5665 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5666 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5667 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5668 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5669 | |
| 5670 | TestCompletionCallback callback; |
| 5671 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5672 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5673 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5674 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5676 | |
| 5677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5679 | |
| 5680 | LoadTimingInfo load_timing_info; |
| 5681 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5682 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5683 | |
| 5684 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5685 | ASSERT_TRUE(response); |
| 5686 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5687 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5688 | |
| 5689 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5690 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5691 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5692 | trans.reset(); |
| 5693 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5694 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5695 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5696 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5698 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5699 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5700 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5701 | |
| 5702 | LoadTimingInfo load_timing_info2; |
| 5703 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5704 | TestLoadTimingReused(load_timing_info2); |
| 5705 | |
| 5706 | // The requests should have the same ID. |
| 5707 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5708 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5709 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5710 | } |
| 5711 | |
| 5712 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5713 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5714 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5715 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5716 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5717 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5718 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5719 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5720 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5721 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5722 | |
| 5723 | HttpRequestInfo request1; |
| 5724 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5725 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5726 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5727 | request1.traffic_annotation = |
| 5728 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5729 | |
| 5730 | HttpRequestInfo request2; |
| 5731 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5732 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5733 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5734 | request2.traffic_annotation = |
| 5735 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5736 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5737 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5738 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5739 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5740 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5741 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5742 | spdy::SpdySerializedFrame get_resp1( |
| 5743 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5744 | spdy::SpdySerializedFrame body1( |
| 5745 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5746 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5747 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5748 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5749 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5750 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5751 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5752 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5753 | spdy::SpdySerializedFrame get_resp2( |
| 5754 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5755 | spdy::SpdySerializedFrame body2( |
| 5756 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5757 | |
| 5758 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5759 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5760 | }; |
| 5761 | |
| 5762 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5763 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5764 | CreateMockRead(body1, 2, ASYNC), |
| 5765 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5766 | CreateMockRead(body2, 5, ASYNC), |
| 5767 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5768 | }; |
| 5769 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5770 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5771 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5772 | |
| 5773 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5774 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5776 | |
| 5777 | TestCompletionCallback callback; |
| 5778 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5779 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5780 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5781 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5782 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5783 | |
| 5784 | LoadTimingInfo load_timing_info; |
| 5785 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5786 | TestLoadTimingNotReused(load_timing_info, |
| 5787 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5788 | |
| 5789 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5790 | ASSERT_TRUE(response); |
| 5791 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5792 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5793 | |
| 5794 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5795 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5796 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5797 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5798 | // Delete the first request, so the second one can reuse the socket. |
| 5799 | trans.reset(); |
| 5800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5801 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5802 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5803 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5804 | |
| 5805 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5806 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5807 | TestLoadTimingReused(load_timing_info2); |
| 5808 | |
| 5809 | // The requests should have the same ID. |
| 5810 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5811 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5812 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5813 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5814 | } |
| 5815 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5816 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5817 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5818 | HttpRequestInfo request; |
| 5819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5820 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5821 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5822 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5823 | request.traffic_annotation = |
| 5824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5825 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5826 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5827 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5828 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5830 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5832 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5833 | // Since we have proxy, should use full url |
| 5834 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5835 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5836 | "Host: www.example.org\r\n" |
| 5837 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5839 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5840 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5841 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5842 | "Host: www.example.org\r\n" |
| 5843 | "Proxy-Connection: keep-alive\r\n" |
| 5844 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5845 | }; |
| 5846 | |
| 5847 | // The proxy responds to the GET with a 407, using a persistent |
| 5848 | // connection. |
| 5849 | MockRead data_reads1[] = { |
| 5850 | // No credentials. |
| 5851 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5852 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5853 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5854 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5855 | |
| 5856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5857 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5858 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5859 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5860 | }; |
| 5861 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5862 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5864 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5867 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5871 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5873 | |
| 5874 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5876 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5877 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5878 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5879 | TestLoadTimingNotReused(load_timing_info, |
| 5880 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5882 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5883 | ASSERT_TRUE(response); |
| 5884 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5885 | EXPECT_EQ(407, response->headers->response_code()); |
| 5886 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5887 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5889 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5891 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5893 | |
| 5894 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5895 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5896 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5897 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5898 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5899 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5900 | TestLoadTimingReused(load_timing_info); |
| 5901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5902 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5903 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5904 | |
| 5905 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5906 | EXPECT_EQ(200, response->headers->response_code()); |
| 5907 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5908 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5909 | |
| 5910 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5911 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5912 | } |
| 5913 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5914 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5915 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5916 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5917 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5918 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 5919 | request.traffic_annotation = |
| 5920 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5921 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5922 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5923 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5924 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5926 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5927 | // Since we have proxy, should try to establish tunnel. |
| 5928 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5929 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5930 | "Host: www.example.org:443\r\n" |
| 5931 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5932 | }; |
| 5933 | |
| 5934 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5935 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5936 | // No response body because the test stops reading here. |
| 5937 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5938 | }; |
| 5939 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5940 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5943 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5947 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5949 | |
| 5950 | rv = callback.WaitForResult(); |
| 5951 | EXPECT_EQ(expected_status, rv); |
| 5952 | } |
| 5953 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5954 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5955 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5956 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5957 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5958 | } |
| 5959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5961 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5962 | } |
| 5963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5964 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5965 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5966 | } |
| 5967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5968 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5969 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5970 | } |
| 5971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5972 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5973 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5974 | } |
| 5975 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5976 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5977 | ConnectStatusHelper( |
| 5978 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5979 | } |
| 5980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5981 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5982 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5983 | } |
| 5984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5985 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5986 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5987 | } |
| 5988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5989 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5990 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5991 | } |
| 5992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5993 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5994 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5995 | } |
| 5996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5997 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5998 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5999 | } |
| 6000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6001 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6002 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6003 | } |
| 6004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6005 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6006 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6007 | } |
| 6008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6009 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6010 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6011 | } |
| 6012 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6013 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6014 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6015 | } |
| 6016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6017 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6018 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6019 | } |
| 6020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6021 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6022 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6023 | } |
| 6024 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6025 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6026 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6027 | } |
| 6028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6029 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6030 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6031 | } |
| 6032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6033 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6034 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6035 | } |
| 6036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6037 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6038 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6039 | } |
| 6040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6041 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6042 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6043 | } |
| 6044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6045 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6046 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6047 | } |
| 6048 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6049 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6050 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6051 | } |
| 6052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6054 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6055 | } |
| 6056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6057 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6058 | ConnectStatusHelperWithExpectedStatus( |
| 6059 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6060 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6061 | } |
| 6062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6063 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6064 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6065 | } |
| 6066 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6067 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6068 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6069 | } |
| 6070 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6071 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6072 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6073 | } |
| 6074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6075 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6076 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6077 | } |
| 6078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6079 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6080 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6081 | } |
| 6082 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6083 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6084 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6085 | } |
| 6086 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6087 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6088 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6089 | } |
| 6090 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6091 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6092 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6093 | } |
| 6094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6095 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6096 | ConnectStatusHelper( |
| 6097 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6098 | } |
| 6099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6100 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6101 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6102 | } |
| 6103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6104 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6105 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6106 | } |
| 6107 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6108 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6109 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6110 | } |
| 6111 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6112 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6113 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6114 | } |
| 6115 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6116 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6117 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6118 | } |
| 6119 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6120 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6121 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6122 | } |
| 6123 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6124 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6125 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6126 | } |
| 6127 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6128 | // Test the flow when both the proxy server AND origin server require |
| 6129 | // authentication. Again, this uses basic auth for both since that is |
| 6130 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6131 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6132 | HttpRequestInfo request; |
| 6133 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6134 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6135 | request.traffic_annotation = |
| 6136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6137 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6138 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6139 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6140 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6142 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6143 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6144 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6145 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6146 | MockWrite( |
| 6147 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6148 | "Host: www.example.org\r\n" |
| 6149 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6150 | }; |
| 6151 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6152 | MockRead data_reads1[] = { |
| 6153 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6154 | // Give a couple authenticate options (only the middle one is actually |
| 6155 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6156 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6157 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6158 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6159 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6160 | // Large content-length -- won't matter, as connection will be reset. |
| 6161 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6162 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6163 | }; |
| 6164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6165 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6166 | // request we should be issuing -- the final header line contains the |
| 6167 | // proxy's credentials. |
| 6168 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6169 | MockWrite( |
| 6170 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6171 | "Host: www.example.org\r\n" |
| 6172 | "Proxy-Connection: keep-alive\r\n" |
| 6173 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6174 | }; |
| 6175 | |
| 6176 | // Now the proxy server lets the request pass through to origin server. |
| 6177 | // The origin server responds with a 401. |
| 6178 | MockRead data_reads2[] = { |
| 6179 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6180 | // Note: We are using the same realm-name as the proxy server. This is |
| 6181 | // completely valid, as realms are unique across hosts. |
| 6182 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6183 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6184 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6185 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6186 | }; |
| 6187 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6188 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6189 | // the credentials for both the proxy and origin server. |
| 6190 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6191 | MockWrite( |
| 6192 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6193 | "Host: www.example.org\r\n" |
| 6194 | "Proxy-Connection: keep-alive\r\n" |
| 6195 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6196 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6197 | }; |
| 6198 | |
| 6199 | // Lastly we get the desired content. |
| 6200 | MockRead data_reads3[] = { |
| 6201 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6202 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6203 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6205 | }; |
| 6206 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6207 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6208 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6209 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6210 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6212 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6214 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6215 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6216 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6218 | |
| 6219 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6223 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6224 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6226 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6228 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6230 | |
| 6231 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6232 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6234 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6235 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6236 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6238 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6240 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6241 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6243 | |
| 6244 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6247 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6248 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6249 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6250 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6251 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6252 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6253 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6254 | // authorization headers. |
| 6255 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6256 | // The NTLM authentication unit tests are based on known test data from the |
| 6257 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6258 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6259 | // for the implementation and testing of the protocol. |
| 6260 | // |
| 6261 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6262 | |
| 6263 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6264 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6265 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6266 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6267 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6268 | request.traffic_annotation = |
| 6269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6270 | |
| 6271 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6272 | // to other auth schemes. |
| 6273 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6274 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6275 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6276 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6278 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6279 | // Generate the NTLM messages based on known test data. |
| 6280 | std::string negotiate_msg; |
| 6281 | std::string challenge_msg; |
| 6282 | std::string authenticate_msg; |
| 6283 | base::Base64Encode( |
| 6284 | base::StringPiece( |
| 6285 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6286 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6287 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6288 | base::Base64Encode( |
| 6289 | base::StringPiece( |
| 6290 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6291 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6292 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6293 | base::Base64Encode( |
| 6294 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6295 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6296 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6297 | arraysize( |
| 6298 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6299 | &authenticate_msg); |
| 6300 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6301 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6302 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6303 | "Host: server\r\n" |
| 6304 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6305 | }; |
| 6306 | |
| 6307 | MockRead data_reads1[] = { |
| 6308 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6309 | // Negotiate and NTLM are often requested together. However, we only want |
| 6310 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6311 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6312 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6313 | MockRead("Connection: close\r\n"), |
| 6314 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6315 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6316 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6317 | }; |
| 6318 | |
| 6319 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6320 | // After restarting with a null identity, this is the |
| 6321 | // request we should be issuing -- the final header line contains a Type |
| 6322 | // 1 message. |
| 6323 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6324 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6325 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6326 | "Authorization: NTLM "), |
| 6327 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6328 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6329 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6330 | // (using correct credentials). The second request continues on the |
| 6331 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6332 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6333 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6334 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6335 | "Authorization: NTLM "), |
| 6336 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6337 | }; |
| 6338 | |
| 6339 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6340 | // The origin server responds with a Type 2 message. |
| 6341 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6342 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6343 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6344 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6345 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6346 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6347 | // Lastly we get the desired content. |
| 6348 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6349 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6350 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6351 | }; |
| 6352 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6353 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6354 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6355 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6356 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6357 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6358 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6360 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6361 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6363 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6365 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6367 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6369 | |
| 6370 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6375 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6376 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6377 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6379 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6380 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6381 | rv = trans.RestartWithAuth( |
| 6382 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6383 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6385 | |
| 6386 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6389 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6391 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6392 | ASSERT_TRUE(response); |
| 6393 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6395 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6397 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6398 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6399 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6400 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6401 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6403 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6404 | ASSERT_TRUE(response); |
| 6405 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6406 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6407 | |
| 6408 | std::string response_data; |
| 6409 | rv = ReadTransaction(&trans, &response_data); |
| 6410 | EXPECT_THAT(rv, IsOk()); |
| 6411 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6412 | |
| 6413 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6414 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6415 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6416 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6417 | } |
| 6418 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6419 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6420 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6421 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6422 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6423 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6424 | request.traffic_annotation = |
| 6425 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6426 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6427 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6428 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6430 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6431 | // Generate the NTLM messages based on known test data. |
| 6432 | std::string negotiate_msg; |
| 6433 | std::string challenge_msg; |
| 6434 | std::string authenticate_msg; |
| 6435 | base::Base64Encode( |
| 6436 | base::StringPiece( |
| 6437 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6438 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6439 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6440 | base::Base64Encode( |
| 6441 | base::StringPiece( |
| 6442 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6443 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6444 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6445 | base::Base64Encode( |
| 6446 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6447 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6448 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6449 | arraysize( |
| 6450 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6451 | &authenticate_msg); |
| 6452 | |
| 6453 | // The authenticate message when |kWrongPassword| is sent. |
| 6454 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6455 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6456 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6457 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6458 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6459 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6460 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6461 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6462 | // Sanity check that it's the same length as the correct authenticate message |
| 6463 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6464 | ASSERT_EQ(authenticate_msg.length(), |
| 6465 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6466 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6467 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6468 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6469 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6470 | "Host: server\r\n" |
| 6471 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6472 | }; |
| 6473 | |
| 6474 | MockRead data_reads1[] = { |
| 6475 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6476 | // Negotiate and NTLM are often requested together. However, we only want |
| 6477 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6478 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6479 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6480 | MockRead("Connection: close\r\n"), |
| 6481 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6482 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6483 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6484 | }; |
| 6485 | |
| 6486 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6487 | // After restarting with a null identity, this is the |
| 6488 | // request we should be issuing -- the final header line contains a Type |
| 6489 | // 1 message. |
| 6490 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6491 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6492 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6493 | "Authorization: NTLM "), |
| 6494 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6496 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6497 | // (using incorrect credentials). The second request continues on the |
| 6498 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6499 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6500 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6501 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6502 | "Authorization: NTLM "), |
| 6503 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6504 | }; |
| 6505 | |
| 6506 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6507 | // The origin server responds with a Type 2 message. |
| 6508 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6509 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6510 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6511 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6512 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6513 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6514 | // Wrong password. |
| 6515 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6516 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6517 | MockRead("Content-Length: 42\r\n"), |
| 6518 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6519 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6520 | }; |
| 6521 | |
| 6522 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6523 | // After restarting with a null identity, this is the |
| 6524 | // request we should be issuing -- the final header line contains a Type |
| 6525 | // 1 message. |
| 6526 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6527 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6528 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6529 | "Authorization: NTLM "), |
| 6530 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6532 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6533 | // (the credentials for the origin server). The second request continues |
| 6534 | // on the same connection. |
| 6535 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6536 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6537 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6538 | "Authorization: NTLM "), |
| 6539 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6540 | }; |
| 6541 | |
| 6542 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6543 | // The origin server responds with a Type 2 message. |
| 6544 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6545 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6546 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6547 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6548 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6549 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6550 | // Lastly we get the desired content. |
| 6551 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6552 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6553 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6554 | }; |
| 6555 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6556 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6557 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6558 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6560 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6561 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6562 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6563 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6565 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6567 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6570 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6572 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6574 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6576 | |
| 6577 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6578 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6580 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6583 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6584 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6585 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6586 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6587 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6588 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6589 | rv = trans.RestartWithAuth( |
| 6590 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6591 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6593 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6594 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6595 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6597 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6598 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6599 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6601 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6602 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6603 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6604 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6605 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6606 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6607 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6609 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6610 | |
| 6611 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6612 | rv = trans.RestartWithAuth( |
| 6613 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6614 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6616 | |
| 6617 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6620 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6622 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6623 | |
| 6624 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6625 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6627 | |
| 6628 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6629 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6631 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6632 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6633 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6634 | |
| 6635 | std::string response_data; |
| 6636 | rv = ReadTransaction(&trans, &response_data); |
| 6637 | EXPECT_THAT(rv, IsOk()); |
| 6638 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6639 | |
| 6640 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6641 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6642 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6643 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6644 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6645 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6646 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6647 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6648 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6649 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6650 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6651 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6652 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6653 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6654 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6655 | |
| 6656 | HttpRequestInfo request; |
| 6657 | request.method = "GET"; |
| 6658 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6659 | request.traffic_annotation = |
| 6660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6661 | |
| 6662 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6663 | spdy::SpdyHeaderBlock request_headers0( |
| 6664 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6665 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6666 | 1, std::move(request_headers0), LOWEST, true)); |
| 6667 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6668 | spdy::SpdyHeaderBlock response_headers0; |
| 6669 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6670 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6671 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6672 | 1, std::move(response_headers0), true)); |
| 6673 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6674 | // Stream 1 is closed. |
| 6675 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6676 | |
| 6677 | // Generate the NTLM messages based on known test data. |
| 6678 | std::string negotiate_msg; |
| 6679 | std::string challenge_msg; |
| 6680 | std::string authenticate_msg; |
| 6681 | base::Base64Encode( |
| 6682 | base::StringPiece( |
| 6683 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6684 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6685 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6686 | base::Base64Encode( |
| 6687 | base::StringPiece( |
| 6688 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6689 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6690 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6691 | base::Base64Encode( |
| 6692 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6693 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6694 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6695 | arraysize( |
| 6696 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6697 | &authenticate_msg); |
| 6698 | |
| 6699 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6700 | spdy::SpdyHeaderBlock request_headers1( |
| 6701 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6702 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6703 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6704 | 3, std::move(request_headers1), LOWEST, true)); |
| 6705 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6706 | spdy::SpdySerializedFrame rst( |
| 6707 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6708 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6709 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6710 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6711 | |
| 6712 | // Retry yet again using HTTP/1.1. |
| 6713 | MockWrite writes1[] = { |
| 6714 | // After restarting with a null identity, this is the |
| 6715 | // request we should be issuing -- the final header line contains a Type |
| 6716 | // 1 message. |
| 6717 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6718 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6719 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6720 | "Authorization: NTLM "), |
| 6721 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6722 | |
| 6723 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6724 | // (the credentials for the origin server). The second request continues |
| 6725 | // on the same connection. |
| 6726 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6727 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6728 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6729 | "Authorization: NTLM "), |
| 6730 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6731 | }; |
| 6732 | |
| 6733 | MockRead reads1[] = { |
| 6734 | // The origin server responds with a Type 2 message. |
| 6735 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6736 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6737 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6738 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6739 | MockRead("You are not authorized to view this page\r\n"), |
| 6740 | |
| 6741 | // Lastly we get the desired content. |
| 6742 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6743 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6744 | 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] | 6745 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6746 | SequencedSocketData data0(reads0, writes0); |
| 6747 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6748 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6750 | |
| 6751 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6752 | ssl0.next_proto = kProtoHTTP2; |
| 6753 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6754 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6756 | |
| 6757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6759 | |
| 6760 | TestCompletionCallback callback1; |
| 6761 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6763 | |
| 6764 | rv = callback1.WaitForResult(); |
| 6765 | EXPECT_THAT(rv, IsOk()); |
| 6766 | |
| 6767 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6768 | |
| 6769 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6770 | ASSERT_TRUE(response); |
| 6771 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6772 | |
| 6773 | TestCompletionCallback callback2; |
| 6774 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6775 | rv = trans.RestartWithAuth( |
| 6776 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6777 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6779 | |
| 6780 | rv = callback2.WaitForResult(); |
| 6781 | EXPECT_THAT(rv, IsOk()); |
| 6782 | |
| 6783 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6784 | |
| 6785 | response = trans.GetResponseInfo(); |
| 6786 | ASSERT_TRUE(response); |
| 6787 | EXPECT_FALSE(response->auth_challenge); |
| 6788 | |
| 6789 | TestCompletionCallback callback3; |
| 6790 | |
| 6791 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6793 | |
| 6794 | rv = callback3.WaitForResult(); |
| 6795 | EXPECT_THAT(rv, IsOk()); |
| 6796 | |
| 6797 | response = trans.GetResponseInfo(); |
| 6798 | ASSERT_TRUE(response); |
| 6799 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6800 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6801 | |
| 6802 | std::string response_data; |
| 6803 | rv = ReadTransaction(&trans, &response_data); |
| 6804 | EXPECT_THAT(rv, IsOk()); |
| 6805 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6806 | |
| 6807 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6808 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6809 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6810 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6811 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6812 | |
| 6813 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 6814 | // do no retry forever checking for TLS version interference. This is a |
| 6815 | // regression test for https://crbug.com/823387. |
| 6816 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 6817 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 6818 | // https://origin/. |
| 6819 | session_deps_.proxy_resolution_service = |
| 6820 | ProxyResolutionService::CreateFixedFromPacResult( |
| 6821 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6822 | |
| 6823 | SSLConfig config; |
| 6824 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 6825 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 6826 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6827 | |
| 6828 | HttpRequestInfo request; |
| 6829 | request.method = "GET"; |
| 6830 | request.url = GURL("https://origin/"); |
| 6831 | request.traffic_annotation = |
| 6832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6833 | |
| 6834 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6835 | // to other auth schemes. |
| 6836 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6837 | |
| 6838 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6839 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 6840 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6841 | |
| 6842 | // Generate the NTLM messages based on known test data. |
| 6843 | std::string negotiate_msg; |
| 6844 | std::string challenge_msg; |
| 6845 | std::string authenticate_msg; |
| 6846 | base::Base64Encode( |
| 6847 | base::StringPiece( |
| 6848 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6849 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6850 | &negotiate_msg); |
| 6851 | base::Base64Encode( |
| 6852 | base::StringPiece( |
| 6853 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6854 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6855 | &challenge_msg); |
| 6856 | base::Base64Encode( |
| 6857 | base::StringPiece( |
| 6858 | reinterpret_cast<const char*>( |
| 6859 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6860 | arraysize( |
| 6861 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 6862 | &authenticate_msg); |
| 6863 | |
| 6864 | MockWrite data_writes[] = { |
| 6865 | // The initial CONNECT request. |
| 6866 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6867 | "Host: origin:443\r\n" |
| 6868 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6869 | |
| 6870 | // After restarting with an identity. |
| 6871 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6872 | "Host: origin:443\r\n" |
| 6873 | "Proxy-Connection: keep-alive\r\n" |
| 6874 | "Proxy-Authorization: NTLM "), |
| 6875 | MockWrite(negotiate_msg.c_str()), |
| 6876 | // End headers. |
| 6877 | MockWrite("\r\n\r\n"), |
| 6878 | |
| 6879 | // The second restart. |
| 6880 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6881 | "Host: origin:443\r\n" |
| 6882 | "Proxy-Connection: keep-alive\r\n" |
| 6883 | "Proxy-Authorization: NTLM "), |
| 6884 | MockWrite(authenticate_msg.c_str()), |
| 6885 | // End headers. |
| 6886 | MockWrite("\r\n\r\n"), |
| 6887 | }; |
| 6888 | |
| 6889 | MockRead data_reads[] = { |
| 6890 | // The initial NTLM response. |
| 6891 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6892 | "Content-Length: 0\r\n" |
| 6893 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 6894 | |
| 6895 | // The NTLM challenge message. |
| 6896 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6897 | "Content-Length: 0\r\n" |
| 6898 | "Proxy-Authenticate: NTLM "), |
| 6899 | MockRead(challenge_msg.c_str()), |
| 6900 | // End headers. |
| 6901 | MockRead("\r\n\r\n"), |
| 6902 | |
| 6903 | // Finally the tunnel is established. |
| 6904 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 6905 | }; |
| 6906 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6907 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6908 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 6909 | data_ssl.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6910 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6911 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
| 6912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 6914 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6915 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 6916 | |
| 6917 | // Start the transaction. The proxy responds with an NTLM authentication |
| 6918 | // request. |
| 6919 | TestCompletionCallback callback; |
| 6920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6921 | int rv = callback.GetResult( |
| 6922 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 6923 | |
| 6924 | EXPECT_THAT(rv, IsOk()); |
| 6925 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6926 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6927 | ASSERT_TRUE(response); |
| 6928 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 6929 | |
| 6930 | // Configure credentials. The proxy responds with the challenge message. |
| 6931 | rv = callback.GetResult(trans.RestartWithAuth( |
| 6932 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6933 | callback.callback())); |
| 6934 | EXPECT_THAT(rv, IsOk()); |
| 6935 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6936 | response = trans.GetResponseInfo(); |
| 6937 | ASSERT_TRUE(response); |
| 6938 | EXPECT_FALSE(response->auth_challenge); |
| 6939 | |
| 6940 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 6941 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 6942 | // restart the process. The proxy responds with another NTLM authentiation |
| 6943 | // request, but we don't need to provide credentials as the cached ones work/ |
| 6944 | rv = callback.GetResult( |
| 6945 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6946 | EXPECT_THAT(rv, IsOk()); |
| 6947 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6948 | response = trans.GetResponseInfo(); |
| 6949 | ASSERT_TRUE(response); |
| 6950 | EXPECT_FALSE(response->auth_challenge); |
| 6951 | |
| 6952 | // The proxy responds with the NTLM challenge message. |
| 6953 | rv = callback.GetResult( |
| 6954 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6955 | EXPECT_THAT(rv, IsOk()); |
| 6956 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6957 | response = trans.GetResponseInfo(); |
| 6958 | ASSERT_TRUE(response); |
| 6959 | EXPECT_FALSE(response->auth_challenge); |
| 6960 | |
| 6961 | // Send the NTLM authenticate message. The tunnel is established and the |
| 6962 | // handshake resets again. We should not retry again. |
| 6963 | rv = callback.GetResult( |
| 6964 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6965 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 6966 | } |
| 6967 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6968 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6969 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6970 | // Test reading a server response which has only headers, and no body. |
| 6971 | // After some maximum number of bytes is consumed, the transaction should |
| 6972 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6973 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6974 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6975 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6976 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 6977 | request.traffic_annotation = |
| 6978 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6982 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6983 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6984 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6985 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6986 | |
| 6987 | MockRead data_reads[] = { |
| 6988 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6989 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6990 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6991 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6992 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6993 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6996 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6997 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6998 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7000 | |
| 7001 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7002 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7003 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7004 | |
| 7005 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7006 | // establish tunnel. |
| 7007 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7008 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7009 | HttpRequestInfo request; |
| 7010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7011 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7012 | request.traffic_annotation = |
| 7013 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7014 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7015 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7016 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7017 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7020 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7021 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7022 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7023 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7024 | // Since we have proxy, should try to establish tunnel. |
| 7025 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7026 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7027 | "Host: www.example.org:443\r\n" |
| 7028 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7029 | }; |
| 7030 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7031 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7032 | // connection. Usually a proxy would return 501 (not implemented), |
| 7033 | // or 200 (tunnel established). |
| 7034 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7035 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7036 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7037 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7038 | }; |
| 7039 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7040 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7041 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7043 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7045 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7047 | |
| 7048 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7049 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7050 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7051 | // Empty the current queue. This is necessary because idle sockets are |
| 7052 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7053 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7054 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7055 | // We now check to make sure the TCPClientSocket was not added back to |
| 7056 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7057 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7058 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7059 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7060 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7061 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7062 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7063 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7064 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7065 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7066 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7067 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7068 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7069 | request.traffic_annotation = |
| 7070 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7071 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7072 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7075 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7076 | MockRead data_reads[] = { |
| 7077 | // A part of the response body is received with the response headers. |
| 7078 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7079 | // The rest of the response body is received in two parts. |
| 7080 | MockRead("lo"), |
| 7081 | MockRead(" world"), |
| 7082 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7083 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7084 | }; |
| 7085 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7086 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7087 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7089 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7090 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7091 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7093 | |
| 7094 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7097 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7098 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7099 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7100 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7101 | std::string status_line = response->headers->GetStatusLine(); |
| 7102 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7103 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7104 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7105 | |
| 7106 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7107 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7109 | EXPECT_EQ("hello world", response_data); |
| 7110 | |
| 7111 | // Empty the current queue. This is necessary because idle sockets are |
| 7112 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7113 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7114 | |
| 7115 | // 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] | 7116 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7117 | } |
| 7118 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7119 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7120 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7121 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7122 | HttpRequestInfo request; |
| 7123 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7124 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7125 | request.traffic_annotation = |
| 7126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7127 | |
| 7128 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7129 | MockWrite( |
| 7130 | "GET / HTTP/1.1\r\n" |
| 7131 | "Host: www.example.org\r\n" |
| 7132 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7133 | }; |
| 7134 | |
| 7135 | MockRead data_reads[] = { |
| 7136 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7137 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7138 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7139 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7140 | }; |
| 7141 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7142 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7144 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7145 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7148 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7154 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7156 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7159 | ASSERT_TRUE(response); |
| 7160 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7161 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7162 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7163 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7164 | |
| 7165 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7166 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7167 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7168 | EXPECT_EQ("hello world", response_data); |
| 7169 | |
| 7170 | // Empty the current queue. This is necessary because idle sockets are |
| 7171 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7172 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7173 | |
| 7174 | // 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] | 7175 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7176 | } |
| 7177 | |
| 7178 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7179 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7180 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7181 | HttpRequestInfo request; |
| 7182 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7183 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7184 | request.traffic_annotation = |
| 7185 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7186 | |
| 7187 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7188 | MockWrite( |
| 7189 | "GET / HTTP/1.1\r\n" |
| 7190 | "Host: www.example.org\r\n" |
| 7191 | "Connection: keep-alive\r\n\r\n"), |
| 7192 | MockWrite( |
| 7193 | "GET / HTTP/1.1\r\n" |
| 7194 | "Host: www.example.org\r\n" |
| 7195 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7196 | }; |
| 7197 | |
| 7198 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7199 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7200 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7201 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7202 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7203 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7205 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7206 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7207 | StaticSocketDataProvider data(data_reads, data_writes); |
| 7208 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7209 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7210 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7212 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7213 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7215 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7216 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7218 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7219 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7221 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7222 | |
| 7223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7224 | ASSERT_TRUE(response); |
| 7225 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7226 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7227 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7228 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7229 | |
| 7230 | std::string response_data; |
| 7231 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7232 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7233 | EXPECT_EQ("hello world", response_data); |
| 7234 | |
| 7235 | // Empty the current queue. This is necessary because idle sockets are |
| 7236 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7237 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7238 | |
| 7239 | // 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] | 7240 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7241 | |
| 7242 | // Now start the second transaction, which should reuse the previous socket. |
| 7243 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7244 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7245 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7246 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7247 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7248 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7250 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7251 | |
| 7252 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7253 | ASSERT_TRUE(response); |
| 7254 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7255 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7256 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7257 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7258 | |
| 7259 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7261 | EXPECT_EQ("hello world", response_data); |
| 7262 | |
| 7263 | // Empty the current queue. This is necessary because idle sockets are |
| 7264 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7265 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7266 | |
| 7267 | // 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] | 7268 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7269 | } |
| 7270 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7271 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7272 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7273 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7274 | HttpRequestInfo request; |
| 7275 | request.method = "GET"; |
| 7276 | request.url = GURL("http://www.example.org/"); |
| 7277 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7278 | request.traffic_annotation = |
| 7279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7280 | |
| 7281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7284 | |
| 7285 | MockRead data_reads[] = { |
| 7286 | // A part of the response body is received with the response headers. |
| 7287 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7288 | // The rest of the response body is received in two parts. |
| 7289 | MockRead("lo"), MockRead(" world"), |
| 7290 | MockRead("junk"), // Should not be read!! |
| 7291 | MockRead(SYNCHRONOUS, OK), |
| 7292 | }; |
| 7293 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7294 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7296 | |
| 7297 | TestCompletionCallback callback; |
| 7298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7299 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7301 | |
| 7302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7305 | ASSERT_TRUE(response); |
| 7306 | EXPECT_TRUE(response->headers); |
| 7307 | std::string status_line = response->headers->GetStatusLine(); |
| 7308 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7309 | |
| 7310 | // Make memory critical notification and ensure the transaction still has been |
| 7311 | // operating right. |
| 7312 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7313 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7314 | base::RunLoop().RunUntilIdle(); |
| 7315 | |
| 7316 | // Socket should not be flushed as long as it is not idle. |
| 7317 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7318 | |
| 7319 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7320 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7321 | EXPECT_THAT(rv, IsOk()); |
| 7322 | EXPECT_EQ("hello world", response_data); |
| 7323 | |
| 7324 | // Empty the current queue. This is necessary because idle sockets are |
| 7325 | // added to the connection pool asynchronously with a PostTask. |
| 7326 | base::RunLoop().RunUntilIdle(); |
| 7327 | |
| 7328 | // We now check to make sure the socket was added back to the pool. |
| 7329 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7330 | |
| 7331 | // Idle sockets should be flushed now. |
| 7332 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7333 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7334 | base::RunLoop().RunUntilIdle(); |
| 7335 | |
| 7336 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7337 | } |
| 7338 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7339 | // Disable idle socket closing on memory pressure. |
| 7340 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7341 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7342 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7343 | HttpRequestInfo request; |
| 7344 | request.method = "GET"; |
| 7345 | request.url = GURL("http://www.example.org/"); |
| 7346 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7347 | request.traffic_annotation = |
| 7348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7349 | |
| 7350 | // Disable idle socket closing on memory pressure. |
| 7351 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7353 | |
| 7354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7355 | |
| 7356 | MockRead data_reads[] = { |
| 7357 | // A part of the response body is received with the response headers. |
| 7358 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7359 | // The rest of the response body is received in two parts. |
| 7360 | MockRead("lo"), MockRead(" world"), |
| 7361 | MockRead("junk"), // Should not be read!! |
| 7362 | MockRead(SYNCHRONOUS, OK), |
| 7363 | }; |
| 7364 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7365 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7366 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7367 | |
| 7368 | TestCompletionCallback callback; |
| 7369 | |
| 7370 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7372 | |
| 7373 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7374 | |
| 7375 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7376 | ASSERT_TRUE(response); |
| 7377 | EXPECT_TRUE(response->headers); |
| 7378 | std::string status_line = response->headers->GetStatusLine(); |
| 7379 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7380 | |
| 7381 | // Make memory critical notification and ensure the transaction still has been |
| 7382 | // operating right. |
| 7383 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7384 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7385 | base::RunLoop().RunUntilIdle(); |
| 7386 | |
| 7387 | // Socket should not be flushed as long as it is not idle. |
| 7388 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7389 | |
| 7390 | std::string response_data; |
| 7391 | rv = ReadTransaction(&trans, &response_data); |
| 7392 | EXPECT_THAT(rv, IsOk()); |
| 7393 | EXPECT_EQ("hello world", response_data); |
| 7394 | |
| 7395 | // Empty the current queue. This is necessary because idle sockets are |
| 7396 | // added to the connection pool asynchronously with a PostTask. |
| 7397 | base::RunLoop().RunUntilIdle(); |
| 7398 | |
| 7399 | // We now check to make sure the socket was added back to the pool. |
| 7400 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7401 | |
| 7402 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7403 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7404 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7405 | base::RunLoop().RunUntilIdle(); |
| 7406 | |
| 7407 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7408 | |
| 7409 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7410 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7411 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7412 | base::RunLoop().RunUntilIdle(); |
| 7413 | |
| 7414 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7415 | } |
| 7416 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7417 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7418 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7419 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7420 | HttpRequestInfo request; |
| 7421 | request.method = "GET"; |
| 7422 | request.url = GURL("https://www.example.org/"); |
| 7423 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7424 | request.traffic_annotation = |
| 7425 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7426 | |
| 7427 | MockWrite data_writes[] = { |
| 7428 | MockWrite("GET / HTTP/1.1\r\n" |
| 7429 | "Host: www.example.org\r\n" |
| 7430 | "Connection: keep-alive\r\n\r\n"), |
| 7431 | }; |
| 7432 | |
| 7433 | MockRead data_reads[] = { |
| 7434 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7435 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7436 | |
| 7437 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7439 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7440 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7442 | |
| 7443 | TestCompletionCallback callback; |
| 7444 | |
| 7445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7447 | |
| 7448 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7449 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7450 | |
| 7451 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7454 | ASSERT_TRUE(response); |
| 7455 | ASSERT_TRUE(response->headers); |
| 7456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7457 | |
| 7458 | // Make memory critical notification and ensure the transaction still has been |
| 7459 | // operating right. |
| 7460 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7461 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7462 | base::RunLoop().RunUntilIdle(); |
| 7463 | |
| 7464 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7465 | |
| 7466 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7467 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7468 | EXPECT_THAT(rv, IsOk()); |
| 7469 | EXPECT_EQ("hello world", response_data); |
| 7470 | |
| 7471 | // Empty the current queue. This is necessary because idle sockets are |
| 7472 | // added to the connection pool asynchronously with a PostTask. |
| 7473 | base::RunLoop().RunUntilIdle(); |
| 7474 | |
| 7475 | // We now check to make sure the socket was added back to the pool. |
| 7476 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7477 | |
| 7478 | // Make memory notification once again and ensure idle socket is closed. |
| 7479 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7480 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7481 | base::RunLoop().RunUntilIdle(); |
| 7482 | |
| 7483 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7484 | } |
| 7485 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7486 | // Make sure that we recycle a socket after a zero-length response. |
| 7487 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7488 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7489 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7490 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7491 | request.url = GURL( |
| 7492 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7493 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7494 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7495 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7496 | request.traffic_annotation = |
| 7497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7500 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7501 | MockRead data_reads[] = { |
| 7502 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7503 | "Content-Length: 0\r\n" |
| 7504 | "Content-Type: text/html\r\n\r\n"), |
| 7505 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7506 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7507 | }; |
| 7508 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7509 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7510 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7511 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7512 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7513 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7516 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7517 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7518 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7520 | |
| 7521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7524 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7525 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7526 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7527 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7528 | std::string status_line = response->headers->GetStatusLine(); |
| 7529 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7530 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7531 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7532 | |
| 7533 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7534 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7535 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7536 | EXPECT_EQ("", response_data); |
| 7537 | |
| 7538 | // Empty the current queue. This is necessary because idle sockets are |
| 7539 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7540 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7541 | |
| 7542 | // 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] | 7543 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7544 | } |
| 7545 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7546 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7547 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7548 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7549 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7550 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7551 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7552 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7553 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7554 | // after use. |
| 7555 | request[0].method = "GET"; |
| 7556 | request[0].url = GURL("http://www.google.com/"); |
| 7557 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7558 | request[0].traffic_annotation = |
| 7559 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7560 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7561 | // transaction 1. The first attempts fails when writing the POST data. |
| 7562 | // This causes the transaction to retry with a new socket. The second |
| 7563 | // attempt succeeds. |
| 7564 | request[1].method = "POST"; |
| 7565 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7566 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7567 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7568 | request[1].traffic_annotation = |
| 7569 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7570 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7572 | |
| 7573 | // The first socket is used for transaction 1 and the first attempt of |
| 7574 | // transaction 2. |
| 7575 | |
| 7576 | // The response of transaction 1. |
| 7577 | MockRead data_reads1[] = { |
| 7578 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7579 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7580 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7581 | }; |
| 7582 | // The mock write results of transaction 1 and the first attempt of |
| 7583 | // transaction 2. |
| 7584 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7585 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7586 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7587 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7588 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7589 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7590 | |
| 7591 | // The second socket is used for the second attempt of transaction 2. |
| 7592 | |
| 7593 | // The response of transaction 2. |
| 7594 | MockRead data_reads2[] = { |
| 7595 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7596 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7597 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7598 | }; |
| 7599 | // The mock write results of the second attempt of transaction 2. |
| 7600 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7601 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7602 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7603 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7604 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7605 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7606 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7607 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7608 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7609 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7610 | "hello world", "welcome" |
| 7611 | }; |
| 7612 | |
| 7613 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7614 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7616 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7617 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7618 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7620 | |
| 7621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7622 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7625 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7626 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7627 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7628 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7629 | |
| 7630 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7631 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7633 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7634 | } |
| 7635 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7636 | |
| 7637 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7638 | // 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] | 7639 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7640 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7641 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7643 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7644 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7645 | request.traffic_annotation = |
| 7646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7650 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7651 | // The password contains an escaped character -- for this test to pass it |
| 7652 | // will need to be unescaped by HttpNetworkTransaction. |
| 7653 | EXPECT_EQ("b%40r", request.url.password()); |
| 7654 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7655 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7656 | MockWrite( |
| 7657 | "GET / HTTP/1.1\r\n" |
| 7658 | "Host: www.example.org\r\n" |
| 7659 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7660 | }; |
| 7661 | |
| 7662 | MockRead data_reads1[] = { |
| 7663 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7664 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7665 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7666 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7667 | }; |
| 7668 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7669 | // After the challenge above, the transaction will be restarted using the |
| 7670 | // identity from the url (foo, b@r) to answer the challenge. |
| 7671 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7672 | MockWrite( |
| 7673 | "GET / HTTP/1.1\r\n" |
| 7674 | "Host: www.example.org\r\n" |
| 7675 | "Connection: keep-alive\r\n" |
| 7676 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7677 | }; |
| 7678 | |
| 7679 | MockRead data_reads2[] = { |
| 7680 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7681 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7682 | MockRead(SYNCHRONOUS, OK), |
| 7683 | }; |
| 7684 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7685 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7686 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7687 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7688 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7690 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7691 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7693 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7694 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7695 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7696 | |
| 7697 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7698 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7700 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7701 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7702 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7703 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7704 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7705 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7706 | |
| 7707 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7708 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7709 | |
| 7710 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7711 | |
| 7712 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7713 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7714 | } |
| 7715 | |
| 7716 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7717 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7718 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7719 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7720 | HttpRequestInfo request; |
| 7721 | request.method = "GET"; |
| 7722 | // Note: the URL has a username:password in it. The password "baz" is |
| 7723 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7724 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7725 | |
| 7726 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7727 | request.traffic_annotation = |
| 7728 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7729 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7730 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7731 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7732 | |
| 7733 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7734 | MockWrite( |
| 7735 | "GET / HTTP/1.1\r\n" |
| 7736 | "Host: www.example.org\r\n" |
| 7737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7738 | }; |
| 7739 | |
| 7740 | MockRead data_reads1[] = { |
| 7741 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7742 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7743 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7744 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7745 | }; |
| 7746 | |
| 7747 | // After the challenge above, the transaction will be restarted using the |
| 7748 | // identity from the url (foo, baz) to answer the challenge. |
| 7749 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7750 | MockWrite( |
| 7751 | "GET / HTTP/1.1\r\n" |
| 7752 | "Host: www.example.org\r\n" |
| 7753 | "Connection: keep-alive\r\n" |
| 7754 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7755 | }; |
| 7756 | |
| 7757 | MockRead data_reads2[] = { |
| 7758 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7759 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7760 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7761 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7762 | }; |
| 7763 | |
| 7764 | // After the challenge above, the transaction will be restarted using the |
| 7765 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7766 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7767 | MockWrite( |
| 7768 | "GET / HTTP/1.1\r\n" |
| 7769 | "Host: www.example.org\r\n" |
| 7770 | "Connection: keep-alive\r\n" |
| 7771 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7772 | }; |
| 7773 | |
| 7774 | MockRead data_reads3[] = { |
| 7775 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7776 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7777 | MockRead(SYNCHRONOUS, OK), |
| 7778 | }; |
| 7779 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7780 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7781 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7782 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7783 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7784 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7785 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7786 | |
| 7787 | TestCompletionCallback callback1; |
| 7788 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7789 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7791 | |
| 7792 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7793 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7795 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7796 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7797 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7799 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7800 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7801 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7804 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7805 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7806 | |
| 7807 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7808 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7810 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7811 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7812 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7814 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7815 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7816 | |
| 7817 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7818 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7819 | |
| 7820 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7821 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7822 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7823 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7824 | } |
| 7825 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7826 | |
| 7827 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7828 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7829 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7830 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7831 | HttpRequestInfo request; |
| 7832 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7833 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7834 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7835 | request.traffic_annotation = |
| 7836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7837 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7840 | |
| 7841 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7842 | MockWrite( |
| 7843 | "GET / HTTP/1.1\r\n" |
| 7844 | "Host: www.example.org\r\n" |
| 7845 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7846 | }; |
| 7847 | |
| 7848 | MockRead data_reads1[] = { |
| 7849 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7850 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7851 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7852 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7853 | }; |
| 7854 | |
| 7855 | // After the challenge above, the transaction will be restarted using the |
| 7856 | // identity supplied by the user, not the one in the URL, to answer the |
| 7857 | // challenge. |
| 7858 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7859 | MockWrite( |
| 7860 | "GET / HTTP/1.1\r\n" |
| 7861 | "Host: www.example.org\r\n" |
| 7862 | "Connection: keep-alive\r\n" |
| 7863 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7864 | }; |
| 7865 | |
| 7866 | MockRead data_reads3[] = { |
| 7867 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7868 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7869 | MockRead(SYNCHRONOUS, OK), |
| 7870 | }; |
| 7871 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7872 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7873 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7874 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7875 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7876 | |
| 7877 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7878 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7879 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7880 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7881 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7882 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7884 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7885 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7886 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7887 | |
| 7888 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7889 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7891 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7892 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7893 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7895 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7896 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7897 | |
| 7898 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7899 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7900 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7901 | |
| 7902 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7903 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7904 | } |
| 7905 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7906 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7907 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7909 | |
| 7910 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7911 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7912 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7914 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7915 | request.traffic_annotation = |
| 7916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7919 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7920 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7921 | MockWrite( |
| 7922 | "GET /x/y/z HTTP/1.1\r\n" |
| 7923 | "Host: www.example.org\r\n" |
| 7924 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7925 | }; |
| 7926 | |
| 7927 | MockRead data_reads1[] = { |
| 7928 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7929 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7930 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7931 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7932 | }; |
| 7933 | |
| 7934 | // Resend with authorization (username=foo, password=bar) |
| 7935 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7936 | MockWrite( |
| 7937 | "GET /x/y/z HTTP/1.1\r\n" |
| 7938 | "Host: www.example.org\r\n" |
| 7939 | "Connection: keep-alive\r\n" |
| 7940 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7941 | }; |
| 7942 | |
| 7943 | // Sever accepts the authorization. |
| 7944 | MockRead data_reads2[] = { |
| 7945 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7946 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7947 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7948 | }; |
| 7949 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7950 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7951 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7953 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7955 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7957 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7959 | |
| 7960 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7963 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7964 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7965 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7967 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7969 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7970 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7972 | |
| 7973 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7974 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7976 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7977 | ASSERT_TRUE(response); |
| 7978 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7979 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7980 | } |
| 7981 | |
| 7982 | // ------------------------------------------------------------------------ |
| 7983 | |
| 7984 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7985 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7986 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7987 | request.method = "GET"; |
| 7988 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7989 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7990 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 7991 | request.traffic_annotation = |
| 7992 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7995 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7996 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7997 | MockWrite( |
| 7998 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7999 | "Host: www.example.org\r\n" |
| 8000 | "Connection: keep-alive\r\n" |
| 8001 | // Send preemptive authorization for MyRealm1 |
| 8002 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8003 | }; |
| 8004 | |
| 8005 | // The server didn't like the preemptive authorization, and |
| 8006 | // challenges us for a different realm (MyRealm2). |
| 8007 | MockRead data_reads1[] = { |
| 8008 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8009 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8010 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8011 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8012 | }; |
| 8013 | |
| 8014 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8015 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8016 | MockWrite( |
| 8017 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8018 | "Host: www.example.org\r\n" |
| 8019 | "Connection: keep-alive\r\n" |
| 8020 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8021 | }; |
| 8022 | |
| 8023 | // Sever accepts the authorization. |
| 8024 | MockRead data_reads2[] = { |
| 8025 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8026 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8027 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8028 | }; |
| 8029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8030 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8031 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8032 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8033 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8034 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8035 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8036 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8037 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8039 | |
| 8040 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8041 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8043 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8044 | ASSERT_TRUE(response); |
| 8045 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8046 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8047 | EXPECT_EQ("http://www.example.org", |
| 8048 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8049 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8050 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8052 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8054 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8055 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8057 | |
| 8058 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8061 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8062 | ASSERT_TRUE(response); |
| 8063 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8064 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8065 | } |
| 8066 | |
| 8067 | // ------------------------------------------------------------------------ |
| 8068 | |
| 8069 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8070 | // succeed with preemptive authorization. |
| 8071 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8072 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8073 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8074 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8075 | request.traffic_annotation = |
| 8076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8079 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8080 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8081 | MockWrite( |
| 8082 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8083 | "Host: www.example.org\r\n" |
| 8084 | "Connection: keep-alive\r\n" |
| 8085 | // The authorization for MyRealm1 gets sent preemptively |
| 8086 | // (since the url is in the same protection space) |
| 8087 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8088 | }; |
| 8089 | |
| 8090 | // Sever accepts the preemptive authorization |
| 8091 | MockRead data_reads1[] = { |
| 8092 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8093 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8094 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8095 | }; |
| 8096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8097 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8098 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8100 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8102 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8104 | |
| 8105 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8106 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8108 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8109 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8110 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8111 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8112 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8113 | } |
| 8114 | |
| 8115 | // ------------------------------------------------------------------------ |
| 8116 | |
| 8117 | // Transaction 4: request another URL in MyRealm (however the |
| 8118 | // url is not known to belong to the protection space, so no pre-auth). |
| 8119 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8120 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8121 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8122 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8123 | request.traffic_annotation = |
| 8124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8125 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8127 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8128 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8129 | MockWrite( |
| 8130 | "GET /x/1 HTTP/1.1\r\n" |
| 8131 | "Host: www.example.org\r\n" |
| 8132 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8133 | }; |
| 8134 | |
| 8135 | MockRead data_reads1[] = { |
| 8136 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8137 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8138 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8139 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8140 | }; |
| 8141 | |
| 8142 | // Resend with authorization from MyRealm's cache. |
| 8143 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8144 | MockWrite( |
| 8145 | "GET /x/1 HTTP/1.1\r\n" |
| 8146 | "Host: www.example.org\r\n" |
| 8147 | "Connection: keep-alive\r\n" |
| 8148 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8149 | }; |
| 8150 | |
| 8151 | // Sever accepts the authorization. |
| 8152 | MockRead data_reads2[] = { |
| 8153 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8154 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8155 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8156 | }; |
| 8157 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8158 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8159 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8160 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8161 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8163 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8164 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8165 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8167 | |
| 8168 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8169 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8171 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8172 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8173 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8175 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8176 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8177 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8179 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8180 | ASSERT_TRUE(response); |
| 8181 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8182 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8183 | } |
| 8184 | |
| 8185 | // ------------------------------------------------------------------------ |
| 8186 | |
| 8187 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8188 | // cached identity. Should invalidate and re-prompt. |
| 8189 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8190 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8191 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8192 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8193 | request.traffic_annotation = |
| 8194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8197 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8198 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8199 | MockWrite( |
| 8200 | "GET /p/q/t HTTP/1.1\r\n" |
| 8201 | "Host: www.example.org\r\n" |
| 8202 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8203 | }; |
| 8204 | |
| 8205 | MockRead data_reads1[] = { |
| 8206 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8207 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8208 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8209 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8210 | }; |
| 8211 | |
| 8212 | // Resend with authorization from cache for MyRealm. |
| 8213 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8214 | MockWrite( |
| 8215 | "GET /p/q/t HTTP/1.1\r\n" |
| 8216 | "Host: www.example.org\r\n" |
| 8217 | "Connection: keep-alive\r\n" |
| 8218 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8219 | }; |
| 8220 | |
| 8221 | // Sever rejects the authorization. |
| 8222 | MockRead data_reads2[] = { |
| 8223 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8224 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8225 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8226 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8227 | }; |
| 8228 | |
| 8229 | // At this point we should prompt for new credentials for MyRealm. |
| 8230 | // Restart with username=foo3, password=foo4. |
| 8231 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8232 | MockWrite( |
| 8233 | "GET /p/q/t HTTP/1.1\r\n" |
| 8234 | "Host: www.example.org\r\n" |
| 8235 | "Connection: keep-alive\r\n" |
| 8236 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8237 | }; |
| 8238 | |
| 8239 | // Sever accepts the authorization. |
| 8240 | MockRead data_reads3[] = { |
| 8241 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8242 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8243 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8244 | }; |
| 8245 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8246 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8247 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8248 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8249 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8250 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8251 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8253 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8254 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8255 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8257 | |
| 8258 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8261 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8262 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8263 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8265 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8266 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8267 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8269 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8270 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8271 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8272 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8273 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8275 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8276 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8278 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8279 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8282 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8283 | ASSERT_TRUE(response); |
| 8284 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8285 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8286 | } |
| 8287 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8288 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8289 | // Tests that nonce count increments when multiple auth attempts |
| 8290 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8291 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8292 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8293 | new HttpAuthHandlerDigest::Factory(); |
| 8294 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8295 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8296 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8297 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8299 | |
| 8300 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8301 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8302 | HttpRequestInfo request; |
| 8303 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8304 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8305 | request.traffic_annotation = |
| 8306 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8309 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8310 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8311 | MockWrite( |
| 8312 | "GET /x/y/z HTTP/1.1\r\n" |
| 8313 | "Host: www.example.org\r\n" |
| 8314 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8315 | }; |
| 8316 | |
| 8317 | MockRead data_reads1[] = { |
| 8318 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8319 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8320 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8321 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8322 | }; |
| 8323 | |
| 8324 | // Resend with authorization (username=foo, password=bar) |
| 8325 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8326 | MockWrite( |
| 8327 | "GET /x/y/z HTTP/1.1\r\n" |
| 8328 | "Host: www.example.org\r\n" |
| 8329 | "Connection: keep-alive\r\n" |
| 8330 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8331 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8332 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8333 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8334 | }; |
| 8335 | |
| 8336 | // Sever accepts the authorization. |
| 8337 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8338 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8339 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8340 | }; |
| 8341 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8342 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8343 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8344 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8345 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8347 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8348 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8349 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8350 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8351 | |
| 8352 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8353 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8354 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8355 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8356 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8357 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8359 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8361 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8362 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8363 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8364 | |
| 8365 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8366 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8369 | ASSERT_TRUE(response); |
| 8370 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | // ------------------------------------------------------------------------ |
| 8374 | |
| 8375 | // Transaction 2: Request another resource in digestive's protection space. |
| 8376 | // This will preemptively add an Authorization header which should have an |
| 8377 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8378 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8379 | HttpRequestInfo request; |
| 8380 | request.method = "GET"; |
| 8381 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8382 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8383 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8384 | request.traffic_annotation = |
| 8385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8387 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8388 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8389 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8390 | MockWrite( |
| 8391 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8392 | "Host: www.example.org\r\n" |
| 8393 | "Connection: keep-alive\r\n" |
| 8394 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8395 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8396 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8397 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8398 | }; |
| 8399 | |
| 8400 | // Sever accepts the authorization. |
| 8401 | MockRead data_reads1[] = { |
| 8402 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8403 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8404 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8405 | }; |
| 8406 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8407 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8408 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8410 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8412 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8414 | |
| 8415 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8418 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8419 | ASSERT_TRUE(response); |
| 8420 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8421 | } |
| 8422 | } |
| 8423 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8424 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8425 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8426 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8429 | |
| 8430 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8431 | trans.read_buf_ = new IOBuffer(15); |
| 8432 | trans.read_buf_len_ = 15; |
| 8433 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8434 | |
| 8435 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8436 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8437 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8438 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8439 | response->response_time = base::Time::Now(); |
| 8440 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8441 | |
| 8442 | { // Setup state for response_.vary_data |
| 8443 | HttpRequestInfo request; |
| 8444 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8445 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8446 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8447 | request.extra_headers.SetHeader("Foo", "1"); |
| 8448 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8449 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8450 | } |
| 8451 | |
| 8452 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8453 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8454 | |
| 8455 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8456 | EXPECT_FALSE(trans.read_buf_); |
| 8457 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8458 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8459 | EXPECT_FALSE(response->auth_challenge); |
| 8460 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8461 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8462 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8463 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8464 | } |
| 8465 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8466 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8467 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8468 | HttpRequestInfo request; |
| 8469 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8470 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8471 | request.traffic_annotation = |
| 8472 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8476 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8477 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8478 | MockWrite( |
| 8479 | "GET / HTTP/1.1\r\n" |
| 8480 | "Host: www.example.org\r\n" |
| 8481 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8482 | }; |
| 8483 | |
| 8484 | MockRead data_reads[] = { |
| 8485 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8487 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8488 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8489 | }; |
| 8490 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8491 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8492 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8493 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8494 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8495 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8496 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8501 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8502 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8503 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8505 | |
| 8506 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8507 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8509 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8510 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8511 | |
| 8512 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8513 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8515 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8516 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8517 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8518 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8519 | } |
| 8520 | |
| 8521 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8522 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8523 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8524 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8525 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8526 | |
| 8527 | HttpRequestInfo request; |
| 8528 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8529 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8530 | request.traffic_annotation = |
| 8531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8532 | |
| 8533 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8534 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8535 | "Host: www.example.org:443\r\n" |
| 8536 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8537 | }; |
| 8538 | |
| 8539 | MockRead proxy_reads[] = { |
| 8540 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8541 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8542 | }; |
| 8543 | |
| 8544 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8545 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8546 | "Host: www.example.org:443\r\n" |
| 8547 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8548 | MockWrite("GET / HTTP/1.1\r\n" |
| 8549 | "Host: www.example.org\r\n" |
| 8550 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8551 | }; |
| 8552 | |
| 8553 | MockRead data_reads[] = { |
| 8554 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8555 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8556 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8557 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8558 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8559 | }; |
| 8560 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8561 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 8562 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8563 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8564 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8565 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8566 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8571 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8572 | |
| 8573 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8574 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8577 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8578 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8579 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8581 | |
| 8582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8583 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8584 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8585 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8587 | |
| 8588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8589 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8591 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8592 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8593 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8594 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8595 | } |
| 8596 | } |
| 8597 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8598 | |
| 8599 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8600 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8601 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8602 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8603 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8604 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8605 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8606 | |
| 8607 | HttpRequestInfo request; |
| 8608 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8609 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8610 | request.traffic_annotation = |
| 8611 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8612 | |
| 8613 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8614 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8615 | "Host: www.example.org:443\r\n" |
| 8616 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8617 | MockWrite("GET / HTTP/1.1\r\n" |
| 8618 | "Host: www.example.org\r\n" |
| 8619 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8620 | }; |
| 8621 | |
| 8622 | MockRead data_reads[] = { |
| 8623 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8624 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8625 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8626 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8627 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8628 | }; |
| 8629 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8630 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8631 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8632 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8633 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8634 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8638 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8639 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8640 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8643 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8645 | |
| 8646 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8647 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8649 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8650 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8651 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8652 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8653 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8654 | EXPECT_EQ(200, response->headers->response_code()); |
| 8655 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8656 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8657 | |
| 8658 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8660 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8661 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8662 | } |
| 8663 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8664 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8665 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8666 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8667 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8668 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8669 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8670 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8671 | |
| 8672 | HttpRequestInfo request; |
| 8673 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8674 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8675 | request.traffic_annotation = |
| 8676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8677 | |
| 8678 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8679 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8680 | "Host: www.example.org:443\r\n" |
| 8681 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8682 | }; |
| 8683 | |
| 8684 | MockRead data_reads[] = { |
| 8685 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8686 | MockRead("Location: http://login.example.com/\r\n"), |
| 8687 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8688 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8689 | }; |
| 8690 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8691 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8692 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8693 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8696 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8697 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8701 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8704 | |
| 8705 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8706 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8707 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8708 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8709 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8710 | |
| 8711 | EXPECT_EQ(302, response->headers->response_code()); |
| 8712 | std::string url; |
| 8713 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8714 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8715 | |
| 8716 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8717 | // timing for the proxy connection instead of the connection to the host, |
| 8718 | // and no send / receive times. |
| 8719 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8720 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8721 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8722 | |
| 8723 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8724 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8725 | |
| 8726 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8727 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8728 | load_timing_info.proxy_resolve_end); |
| 8729 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8730 | load_timing_info.connect_timing.connect_start); |
| 8731 | ExpectConnectTimingHasTimes( |
| 8732 | load_timing_info.connect_timing, |
| 8733 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8734 | |
| 8735 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8736 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8737 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8738 | } |
| 8739 | |
| 8740 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8741 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8742 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8743 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8744 | |
| 8745 | HttpRequestInfo request; |
| 8746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8747 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8748 | request.traffic_annotation = |
| 8749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8750 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8751 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8752 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8753 | spdy::SpdySerializedFrame goaway( |
| 8754 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8755 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8756 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8757 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8758 | }; |
| 8759 | |
| 8760 | static const char* const kExtraHeaders[] = { |
| 8761 | "location", |
| 8762 | "http://login.example.com/", |
| 8763 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8764 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8765 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8766 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8767 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8768 | }; |
| 8769 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8770 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8771 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8772 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8773 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8777 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8778 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8781 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8782 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8784 | |
| 8785 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8786 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8787 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8788 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8789 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8790 | |
| 8791 | EXPECT_EQ(302, response->headers->response_code()); |
| 8792 | std::string url; |
| 8793 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8794 | EXPECT_EQ("http://login.example.com/", url); |
| 8795 | } |
| 8796 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8797 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8798 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8799 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8800 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8801 | |
| 8802 | HttpRequestInfo request; |
| 8803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8804 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8805 | request.traffic_annotation = |
| 8806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8807 | |
| 8808 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8809 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8810 | "Host: www.example.org:443\r\n" |
| 8811 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8812 | }; |
| 8813 | |
| 8814 | MockRead data_reads[] = { |
| 8815 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8816 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8817 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8819 | }; |
| 8820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8821 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8822 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8823 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8827 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8831 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8832 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8834 | |
| 8835 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8836 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8837 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8838 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8839 | } |
| 8840 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8841 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8842 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8843 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8844 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8845 | |
| 8846 | HttpRequestInfo request; |
| 8847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8848 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8849 | request.traffic_annotation = |
| 8850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8851 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8852 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8853 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8854 | spdy::SpdySerializedFrame rst( |
| 8855 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8856 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8857 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8858 | }; |
| 8859 | |
| 8860 | static const char* const kExtraHeaders[] = { |
| 8861 | "location", |
| 8862 | "http://login.example.com/", |
| 8863 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8864 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8865 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8866 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8867 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8868 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8869 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8870 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8871 | }; |
| 8872 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8873 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8874 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8875 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8876 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8878 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8880 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8881 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8884 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8885 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8886 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8887 | |
| 8888 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8889 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8890 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8891 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8892 | } |
| 8893 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8894 | // Test the request-challenge-retry sequence for basic auth, through |
| 8895 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8896 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8897 | HttpRequestInfo request; |
| 8898 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8899 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8900 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8901 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 8902 | request.traffic_annotation = |
| 8903 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8904 | |
| 8905 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8906 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8907 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8908 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8909 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8910 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8911 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8912 | |
| 8913 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8914 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8915 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8916 | spdy::SpdySerializedFrame rst( |
| 8917 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8918 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8920 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8921 | // be issuing -- the final header line contains the credentials. |
| 8922 | const char* const kAuthCredentials[] = { |
| 8923 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8924 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8925 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8926 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8927 | HostPortPair("www.example.org", 443))); |
| 8928 | // fetch https://www.example.org/ via HTTP |
| 8929 | const char get[] = |
| 8930 | "GET / HTTP/1.1\r\n" |
| 8931 | "Host: www.example.org\r\n" |
| 8932 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8933 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8934 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8935 | |
| 8936 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8937 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8938 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8939 | }; |
| 8940 | |
| 8941 | // The proxy responds to the connect with a 407, using a persistent |
| 8942 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8943 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8944 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8945 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8946 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8947 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8948 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8949 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8950 | spdy::SpdySerializedFrame conn_resp( |
| 8951 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8952 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8953 | "Content-Length: 5\r\n\r\n"; |
| 8954 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8955 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8956 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8957 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8958 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8959 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8960 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8961 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8962 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8963 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8964 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8965 | }; |
| 8966 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8967 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8968 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8969 | // Negotiate SPDY to the proxy |
| 8970 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8971 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8972 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8973 | // Vanilla SSL to the server |
| 8974 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8975 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8976 | |
| 8977 | TestCompletionCallback callback1; |
| 8978 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8979 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8980 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8981 | |
| 8982 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8984 | |
| 8985 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8986 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8987 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8988 | log.GetEntries(&entries); |
| 8989 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8990 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8991 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8992 | ExpectLogContainsSomewhere( |
| 8993 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8994 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8995 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8996 | |
| 8997 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8998 | ASSERT_TRUE(response); |
| 8999 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9000 | EXPECT_EQ(407, response->headers->response_code()); |
| 9001 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9002 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9003 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9004 | |
| 9005 | TestCompletionCallback callback2; |
| 9006 | |
| 9007 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9008 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9010 | |
| 9011 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9012 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9013 | |
| 9014 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9015 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9016 | |
| 9017 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9018 | EXPECT_EQ(200, response->headers->response_code()); |
| 9019 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9020 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9021 | |
| 9022 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9023 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9024 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9025 | LoadTimingInfo load_timing_info; |
| 9026 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9027 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9028 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9029 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9030 | trans.reset(); |
| 9031 | session->CloseAllConnections(); |
| 9032 | } |
| 9033 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9034 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9035 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9036 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9037 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9038 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9039 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9040 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9041 | HttpRequestInfo request; |
| 9042 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9043 | request.traffic_annotation = |
| 9044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9045 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9046 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9047 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9048 | push_request.method = "GET"; |
| 9049 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9050 | push_request.traffic_annotation = |
| 9051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9052 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9053 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9054 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9055 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9056 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9057 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9058 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9059 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9060 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9061 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9062 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9063 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9064 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9065 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9066 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9067 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9068 | |
| 9069 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9070 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9071 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9072 | }; |
| 9073 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9074 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9075 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9076 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9077 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9078 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[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 stream1_body( |
| 9081 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9082 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9083 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9084 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9085 | |
| 9086 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9087 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9088 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9089 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9090 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9091 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9092 | }; |
| 9093 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9094 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9095 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9096 | // Negotiate SPDY to the proxy |
| 9097 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9098 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9100 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9101 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9102 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9103 | TestCompletionCallback callback; |
| 9104 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9106 | |
| 9107 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9109 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9110 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9111 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9112 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9113 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9115 | |
| 9116 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9118 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9119 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9120 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9121 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9122 | |
| 9123 | EXPECT_EQ(200, response->headers->response_code()); |
| 9124 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9125 | |
| 9126 | std::string response_data; |
| 9127 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9128 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9129 | EXPECT_EQ("hello!", response_data); |
| 9130 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9131 | LoadTimingInfo load_timing_info; |
| 9132 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9133 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9134 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9135 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9136 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9137 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9138 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9139 | |
| 9140 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9142 | EXPECT_EQ("pushed", response_data); |
| 9143 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9144 | LoadTimingInfo push_load_timing_info; |
| 9145 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9146 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9147 | // The transactions should share a socket ID, despite being for different |
| 9148 | // origins. |
| 9149 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9150 | push_load_timing_info.socket_log_id); |
| 9151 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9152 | trans.reset(); |
| 9153 | push_trans.reset(); |
| 9154 | session->CloseAllConnections(); |
| 9155 | } |
| 9156 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9157 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9158 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9159 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9160 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9161 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9162 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9163 | HttpRequestInfo request; |
| 9164 | |
| 9165 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9166 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9167 | request.traffic_annotation = |
| 9168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9169 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9170 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9171 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9172 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9173 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9174 | |
| 9175 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9176 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[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 stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9181 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9182 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9183 | spdy::SpdySerializedFrame push_rst( |
| 9184 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9185 | |
| 9186 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9187 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9188 | }; |
| 9189 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9190 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9191 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[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 stream1_body( |
| 9194 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9195 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9196 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9197 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9198 | |
| 9199 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9200 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9201 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9202 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9203 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9204 | }; |
| 9205 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9206 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9207 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9208 | // Negotiate SPDY to the proxy |
| 9209 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9210 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9212 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9213 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9214 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9215 | TestCompletionCallback callback; |
| 9216 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9218 | |
| 9219 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9221 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9222 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9223 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9224 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9225 | |
| 9226 | EXPECT_EQ(200, response->headers->response_code()); |
| 9227 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9228 | |
| 9229 | std::string response_data; |
| 9230 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9231 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9232 | EXPECT_EQ("hello!", response_data); |
| 9233 | |
| 9234 | trans.reset(); |
| 9235 | session->CloseAllConnections(); |
| 9236 | } |
| 9237 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9238 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9239 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9240 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9241 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9242 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9243 | proxy_delegate->set_trusted_spdy_proxy( |
| 9244 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9245 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9246 | HttpRequestInfo request; |
| 9247 | |
| 9248 | request.method = "GET"; |
| 9249 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9250 | request.traffic_annotation = |
| 9251 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9252 | |
| 9253 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9254 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9255 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9256 | BoundTestNetLog log; |
| 9257 | session_deps_.net_log = log.bound().net_log(); |
| 9258 | |
| 9259 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9260 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9261 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9263 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9264 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9265 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9266 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9267 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9268 | |
| 9269 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9270 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9271 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9272 | }; |
| 9273 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9274 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9275 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9276 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9277 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9278 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9279 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9280 | spdy::SpdySerializedFrame stream1_body( |
| 9281 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
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_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9284 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9285 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9286 | spdy::SpdySerializedFrame stream2_body( |
| 9287 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9288 | |
| 9289 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9290 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9291 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9292 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9293 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9294 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9295 | }; |
| 9296 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9297 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9298 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9299 | // Negotiate SPDY to the proxy |
| 9300 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9301 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9303 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9304 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9305 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9306 | TestCompletionCallback callback; |
| 9307 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9309 | |
| 9310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9311 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9312 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9313 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9314 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9315 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9316 | |
| 9317 | EXPECT_EQ(200, response->headers->response_code()); |
| 9318 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9319 | |
| 9320 | std::string response_data; |
| 9321 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9322 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9323 | EXPECT_EQ("hello!", response_data); |
| 9324 | |
| 9325 | trans.reset(); |
| 9326 | session->CloseAllConnections(); |
| 9327 | } |
| 9328 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9329 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9330 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9331 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9332 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9333 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9334 | |
| 9335 | HttpRequestInfo request; |
| 9336 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9337 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9338 | request.traffic_annotation = |
| 9339 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9340 | |
| 9341 | // Attempt to fetch the URL from a server with a bad cert |
| 9342 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9343 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9344 | "Host: www.example.org:443\r\n" |
| 9345 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9346 | }; |
| 9347 | |
| 9348 | MockRead bad_cert_reads[] = { |
| 9349 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9350 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9351 | }; |
| 9352 | |
| 9353 | // Attempt to fetch the URL with a good cert |
| 9354 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9355 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9356 | "Host: www.example.org:443\r\n" |
| 9357 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9358 | MockWrite("GET / HTTP/1.1\r\n" |
| 9359 | "Host: www.example.org\r\n" |
| 9360 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9361 | }; |
| 9362 | |
| 9363 | MockRead good_cert_reads[] = { |
| 9364 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9365 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9366 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9367 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9368 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9369 | }; |
| 9370 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9371 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 9372 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9373 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9374 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9375 | |
| 9376 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9378 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9380 | |
| 9381 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9383 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9384 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9386 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9387 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9390 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9391 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9393 | |
| 9394 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9395 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9397 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9398 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9399 | |
| 9400 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9401 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9403 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9405 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9406 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9407 | } |
| 9408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9409 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9410 | HttpRequestInfo request; |
| 9411 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9412 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9413 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9414 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9415 | request.traffic_annotation = |
| 9416 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9420 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9421 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9422 | MockWrite( |
| 9423 | "GET / HTTP/1.1\r\n" |
| 9424 | "Host: www.example.org\r\n" |
| 9425 | "Connection: keep-alive\r\n" |
| 9426 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9427 | }; |
| 9428 | |
| 9429 | // Lastly, the server responds with the actual content. |
| 9430 | MockRead data_reads[] = { |
| 9431 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9432 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9433 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9435 | }; |
| 9436 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9437 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9440 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9444 | |
| 9445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9447 | } |
| 9448 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9449 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9450 | HttpRequestInfo request; |
| 9451 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9452 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9453 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9454 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9455 | request.traffic_annotation = |
| 9456 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9457 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9458 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9459 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9460 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9461 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9462 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9463 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9464 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9465 | "Host: www.example.org:443\r\n" |
| 9466 | "Proxy-Connection: keep-alive\r\n" |
| 9467 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9468 | }; |
| 9469 | MockRead data_reads[] = { |
| 9470 | // Return an error, so the transaction stops here (this test isn't |
| 9471 | // interested in the rest). |
| 9472 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9473 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9474 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9475 | }; |
| 9476 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9477 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9478 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9480 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9481 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9482 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9483 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9484 | |
| 9485 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9487 | } |
| 9488 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9489 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9490 | HttpRequestInfo request; |
| 9491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9492 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9493 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9494 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9495 | request.traffic_annotation = |
| 9496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9500 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9501 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9502 | MockWrite( |
| 9503 | "GET / HTTP/1.1\r\n" |
| 9504 | "Host: www.example.org\r\n" |
| 9505 | "Connection: keep-alive\r\n" |
| 9506 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9507 | }; |
| 9508 | |
| 9509 | // Lastly, the server responds with the actual content. |
| 9510 | MockRead data_reads[] = { |
| 9511 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9512 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9513 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9514 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9515 | }; |
| 9516 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9517 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9518 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9519 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9520 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9522 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9524 | |
| 9525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9526 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9527 | } |
| 9528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9529 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9530 | HttpRequestInfo request; |
| 9531 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9532 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9533 | request.traffic_annotation = |
| 9534 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9535 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9538 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9539 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9540 | MockWrite( |
| 9541 | "POST / HTTP/1.1\r\n" |
| 9542 | "Host: www.example.org\r\n" |
| 9543 | "Connection: keep-alive\r\n" |
| 9544 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9545 | }; |
| 9546 | |
| 9547 | // Lastly, the server responds with the actual content. |
| 9548 | MockRead data_reads[] = { |
| 9549 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9550 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9551 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9552 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9553 | }; |
| 9554 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9555 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9558 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9562 | |
| 9563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9564 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9565 | } |
| 9566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9567 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9568 | HttpRequestInfo request; |
| 9569 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9570 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9571 | request.traffic_annotation = |
| 9572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9577 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9578 | MockWrite( |
| 9579 | "PUT / HTTP/1.1\r\n" |
| 9580 | "Host: www.example.org\r\n" |
| 9581 | "Connection: keep-alive\r\n" |
| 9582 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9583 | }; |
| 9584 | |
| 9585 | // Lastly, the server responds with the actual content. |
| 9586 | MockRead data_reads[] = { |
| 9587 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9588 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9589 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9590 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9591 | }; |
| 9592 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9593 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9596 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9600 | |
| 9601 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9602 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9603 | } |
| 9604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9605 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9606 | HttpRequestInfo request; |
| 9607 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9608 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9609 | request.traffic_annotation = |
| 9610 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9611 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9614 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9615 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9616 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9617 | "Host: www.example.org\r\n" |
| 9618 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9619 | }; |
| 9620 | |
| 9621 | // Lastly, the server responds with the actual content. |
| 9622 | MockRead data_reads[] = { |
| 9623 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9624 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9625 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9626 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9627 | }; |
| 9628 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9629 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9630 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9632 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9636 | |
| 9637 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9638 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9639 | } |
| 9640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9641 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9642 | HttpRequestInfo request; |
| 9643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9644 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9645 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9646 | request.traffic_annotation = |
| 9647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9648 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9649 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9651 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9652 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9653 | MockWrite( |
| 9654 | "GET / HTTP/1.1\r\n" |
| 9655 | "Host: www.example.org\r\n" |
| 9656 | "Connection: keep-alive\r\n" |
| 9657 | "Pragma: no-cache\r\n" |
| 9658 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9659 | }; |
| 9660 | |
| 9661 | // Lastly, the server responds with the actual content. |
| 9662 | MockRead data_reads[] = { |
| 9663 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9664 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9665 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9667 | }; |
| 9668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9669 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9670 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9672 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9674 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9676 | |
| 9677 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9679 | } |
| 9680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9681 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9682 | HttpRequestInfo request; |
| 9683 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9684 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9685 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9686 | request.traffic_annotation = |
| 9687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9688 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9689 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9691 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9692 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9693 | MockWrite( |
| 9694 | "GET / HTTP/1.1\r\n" |
| 9695 | "Host: www.example.org\r\n" |
| 9696 | "Connection: keep-alive\r\n" |
| 9697 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9698 | }; |
| 9699 | |
| 9700 | // Lastly, the server responds with the actual content. |
| 9701 | MockRead data_reads[] = { |
| 9702 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9703 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9704 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9705 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9706 | }; |
| 9707 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9708 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9711 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9715 | |
| 9716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9718 | } |
| 9719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9720 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9721 | HttpRequestInfo request; |
| 9722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9723 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9724 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9725 | request.traffic_annotation = |
| 9726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9730 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9731 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9732 | MockWrite( |
| 9733 | "GET / HTTP/1.1\r\n" |
| 9734 | "Host: www.example.org\r\n" |
| 9735 | "Connection: keep-alive\r\n" |
| 9736 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9737 | }; |
| 9738 | |
| 9739 | // Lastly, the server responds with the actual content. |
| 9740 | MockRead data_reads[] = { |
| 9741 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9742 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9743 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9744 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9745 | }; |
| 9746 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9747 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9750 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9752 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9754 | |
| 9755 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9756 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9757 | } |
| 9758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9759 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9760 | HttpRequestInfo request; |
| 9761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9762 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9763 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9764 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9765 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9766 | request.traffic_annotation = |
| 9767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9771 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9772 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9773 | MockWrite( |
| 9774 | "GET / HTTP/1.1\r\n" |
| 9775 | "Host: www.example.org\r\n" |
| 9776 | "Connection: keep-alive\r\n" |
| 9777 | "referer: www.foo.com\r\n" |
| 9778 | "hEllo: Kitty\r\n" |
| 9779 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9780 | }; |
| 9781 | |
| 9782 | // Lastly, the server responds with the actual content. |
| 9783 | MockRead data_reads[] = { |
| 9784 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9786 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9788 | }; |
| 9789 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9790 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9793 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9797 | |
| 9798 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9799 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9800 | } |
| 9801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9802 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9803 | HttpRequestInfo request; |
| 9804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9805 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9806 | request.traffic_annotation = |
| 9807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9808 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9809 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9810 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9811 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9812 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9813 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9817 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9818 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9819 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9820 | |
| 9821 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9822 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9823 | MockWrite( |
| 9824 | "GET / HTTP/1.1\r\n" |
| 9825 | "Host: www.example.org\r\n" |
| 9826 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9827 | |
| 9828 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9829 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9830 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9831 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9832 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9833 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9834 | }; |
| 9835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9836 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9839 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9840 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9841 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9843 | |
| 9844 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9845 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9846 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9847 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9848 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9849 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9850 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9851 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9852 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9853 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9854 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9855 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9856 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9857 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9858 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9859 | EXPECT_EQ("Payload", response_text); |
| 9860 | } |
| 9861 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9862 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9863 | HttpRequestInfo request; |
| 9864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9865 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9866 | request.traffic_annotation = |
| 9867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9868 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9869 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9870 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9871 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9872 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9873 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9876 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9877 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9878 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9879 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9880 | |
| 9881 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9882 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9883 | arraysize(write_buffer)), |
| 9884 | MockWrite( |
| 9885 | "GET / HTTP/1.1\r\n" |
| 9886 | "Host: www.example.org\r\n" |
| 9887 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9888 | |
| 9889 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9890 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9891 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9892 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9893 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9894 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9895 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9896 | }; |
| 9897 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9898 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9899 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9900 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9901 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9904 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9906 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9908 | |
| 9909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9910 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9911 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9912 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9913 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9914 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9915 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9917 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9918 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9919 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9920 | |
| 9921 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9922 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9924 | EXPECT_EQ("Payload", response_text); |
| 9925 | } |
| 9926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9927 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9928 | HttpRequestInfo request; |
| 9929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9930 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9931 | request.traffic_annotation = |
| 9932 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9933 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9934 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9935 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9936 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9937 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9941 | |
| 9942 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9943 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9944 | |
| 9945 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9946 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9947 | MockWrite( |
| 9948 | "GET / HTTP/1.1\r\n" |
| 9949 | "Host: www.example.org\r\n" |
| 9950 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9951 | |
| 9952 | MockRead data_reads[] = { |
| 9953 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9954 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9956 | MockRead("Payload"), |
| 9957 | MockRead(SYNCHRONOUS, OK) |
| 9958 | }; |
| 9959 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9960 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9962 | |
| 9963 | TestCompletionCallback callback; |
| 9964 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9965 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9967 | |
| 9968 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9969 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9970 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9971 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9972 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9973 | |
| 9974 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9975 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9976 | TestLoadTimingNotReused(load_timing_info, |
| 9977 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9978 | |
| 9979 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9980 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9981 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9982 | EXPECT_EQ("Payload", response_text); |
| 9983 | } |
| 9984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9985 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9986 | HttpRequestInfo request; |
| 9987 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9988 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 9989 | request.traffic_annotation = |
| 9990 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9991 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9992 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9993 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9994 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9995 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9996 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9997 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9998 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10000 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10001 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10002 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10003 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10004 | 0x05, // Version |
| 10005 | 0x01, // Command (CONNECT) |
| 10006 | 0x00, // Reserved. |
| 10007 | 0x03, // Address type (DOMAINNAME). |
| 10008 | 0x0F, // Length of domain (15) |
| 10009 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10010 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10011 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10012 | const char kSOCKS5OkResponse[] = |
| 10013 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10014 | |
| 10015 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10016 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10017 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10018 | MockWrite( |
| 10019 | "GET / HTTP/1.1\r\n" |
| 10020 | "Host: www.example.org\r\n" |
| 10021 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10022 | |
| 10023 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10024 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10025 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10026 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10027 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10028 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10029 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10030 | }; |
| 10031 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10032 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10033 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10034 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10035 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10036 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10037 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10039 | |
| 10040 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10041 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10043 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10044 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10045 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10046 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10047 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10048 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10049 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10050 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10051 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10052 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10053 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10054 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10055 | EXPECT_EQ("Payload", response_text); |
| 10056 | } |
| 10057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10058 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10059 | HttpRequestInfo request; |
| 10060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10061 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10062 | request.traffic_annotation = |
| 10063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10064 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10065 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10066 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10067 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10068 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10069 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10070 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10072 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10073 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10074 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10075 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10076 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10077 | 0x05, // Version |
| 10078 | 0x01, // Command (CONNECT) |
| 10079 | 0x00, // Reserved. |
| 10080 | 0x03, // Address type (DOMAINNAME). |
| 10081 | 0x0F, // Length of domain (15) |
| 10082 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10083 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10084 | }; |
| 10085 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10086 | const char kSOCKS5OkResponse[] = |
| 10087 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10088 | |
| 10089 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10090 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10091 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10092 | arraysize(kSOCKS5OkRequest)), |
| 10093 | MockWrite( |
| 10094 | "GET / HTTP/1.1\r\n" |
| 10095 | "Host: www.example.org\r\n" |
| 10096 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10097 | |
| 10098 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10099 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10100 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10101 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10102 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10103 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10104 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10105 | }; |
| 10106 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10107 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10109 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10110 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10112 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10113 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10115 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10117 | |
| 10118 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10119 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10121 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10122 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10123 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10124 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10125 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10126 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10127 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10128 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10129 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10130 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10131 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10133 | EXPECT_EQ("Payload", response_text); |
| 10134 | } |
| 10135 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10136 | namespace { |
| 10137 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10138 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10139 | |
| 10140 | struct GroupNameTest { |
| 10141 | std::string proxy_server; |
| 10142 | std::string url; |
| 10143 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10144 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10145 | }; |
| 10146 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10147 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10148 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10150 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10151 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10152 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10153 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10154 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10155 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10156 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10157 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10158 | |
| 10159 | return session; |
| 10160 | } |
| 10161 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10162 | int GroupNameTransactionHelper(const std::string& url, |
| 10163 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10164 | HttpRequestInfo request; |
| 10165 | request.method = "GET"; |
| 10166 | request.url = GURL(url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10167 | request.traffic_annotation = |
| 10168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10170 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10172 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10173 | |
| 10174 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10175 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10176 | } |
| 10177 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10178 | } // namespace |
| 10179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10180 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10181 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10182 | { |
| 10183 | "", // unused |
| 10184 | "http://www.example.org/direct", |
| 10185 | "www.example.org:80", |
| 10186 | false, |
| 10187 | }, |
| 10188 | { |
| 10189 | "", // unused |
| 10190 | "http://[2001:1418:13:1::25]/direct", |
| 10191 | "[2001:1418:13:1::25]:80", |
| 10192 | false, |
| 10193 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10194 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10195 | // SSL Tests |
| 10196 | { |
| 10197 | "", // unused |
| 10198 | "https://www.example.org/direct_ssl", |
| 10199 | "ssl/www.example.org:443", |
| 10200 | true, |
| 10201 | }, |
| 10202 | { |
| 10203 | "", // unused |
| 10204 | "https://[2001:1418:13:1::25]/direct", |
| 10205 | "ssl/[2001:1418:13:1::25]:443", |
| 10206 | true, |
| 10207 | }, |
| 10208 | { |
| 10209 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10210 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10211 | "ssl/host.with.alternate:443", |
| 10212 | true, |
| 10213 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10214 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10215 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10216 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10217 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10218 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10219 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10220 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10221 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10222 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10223 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10224 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10225 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10226 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10227 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10228 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10229 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10230 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10231 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10232 | |
| 10233 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10234 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10235 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10236 | EXPECT_EQ(tests[i].expected_group_name, |
| 10237 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10238 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10239 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10240 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10241 | } |
| 10242 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10243 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10244 | // When SSL proxy is not in use, socket must be requested from |
| 10245 | // |transport_conn_pool|. |
| 10246 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10247 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10248 | } |
| 10249 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10250 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10251 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10252 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10253 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10254 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10255 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10256 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10257 | // SSL Tests |
| 10258 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10259 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10260 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10261 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10262 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10263 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10264 | "http_proxy", "https://host.with.alternate/direct", |
| 10265 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10266 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10267 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10268 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10269 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10270 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10271 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10272 | }; |
| 10273 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10274 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10275 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10276 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10277 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10278 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10279 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10280 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10281 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10282 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10283 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10284 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10285 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10286 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10287 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10288 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10289 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10290 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10291 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10292 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10293 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10294 | |
| 10295 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10296 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10297 | if (tests[i].ssl) |
| 10298 | EXPECT_EQ(tests[i].expected_group_name, |
| 10299 | ssl_conn_pool->last_group_name_received()); |
| 10300 | else |
| 10301 | EXPECT_EQ(tests[i].expected_group_name, |
| 10302 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10303 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10304 | } |
| 10305 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10306 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10307 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10308 | { |
| 10309 | "socks4://socks_proxy:1080", |
| 10310 | "http://www.example.org/socks4_direct", |
| 10311 | "socks4/www.example.org:80", |
| 10312 | false, |
| 10313 | }, |
| 10314 | { |
| 10315 | "socks5://socks_proxy:1080", |
| 10316 | "http://www.example.org/socks5_direct", |
| 10317 | "socks5/www.example.org:80", |
| 10318 | false, |
| 10319 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10320 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10321 | // SSL Tests |
| 10322 | { |
| 10323 | "socks4://socks_proxy:1080", |
| 10324 | "https://www.example.org/socks4_ssl", |
| 10325 | "socks4/ssl/www.example.org:443", |
| 10326 | true, |
| 10327 | }, |
| 10328 | { |
| 10329 | "socks5://socks_proxy:1080", |
| 10330 | "https://www.example.org/socks5_ssl", |
| 10331 | "socks5/ssl/www.example.org:443", |
| 10332 | true, |
| 10333 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10335 | { |
| 10336 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10337 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10338 | "socks4/ssl/host.with.alternate:443", |
| 10339 | true, |
| 10340 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10341 | }; |
| 10342 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10343 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10344 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10345 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10346 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10347 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10348 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10349 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10350 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10351 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10352 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10353 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10354 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10355 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10356 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10357 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10358 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10359 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10360 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10361 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10362 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10363 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10365 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10366 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10367 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10368 | if (tests[i].ssl) |
| 10369 | EXPECT_EQ(tests[i].expected_group_name, |
| 10370 | ssl_conn_pool->last_group_name_received()); |
| 10371 | else |
| 10372 | EXPECT_EQ(tests[i].expected_group_name, |
| 10373 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10374 | } |
| 10375 | } |
| 10376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10377 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10378 | HttpRequestInfo request; |
| 10379 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10380 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10381 | request.traffic_annotation = |
| 10382 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10383 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10384 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10385 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10386 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10387 | // This simulates failure resolving all hostnames; that means we will fail |
| 10388 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10389 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10390 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10394 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10398 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10400 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10401 | } |
| 10402 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10403 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10404 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10405 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10406 | HttpRequestInfo request_info; |
| 10407 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10408 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10409 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10410 | request_info.traffic_annotation = |
| 10411 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10412 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10413 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10414 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10418 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10419 | // 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] | 10420 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10421 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10422 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10423 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10424 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10425 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10426 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10428 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10429 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10430 | |
| 10431 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10432 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10433 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10434 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10435 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10436 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10437 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10438 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10439 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10440 | // 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] | 10441 | // we can tell if the next lookup hit the cache, or the "network". |
| 10442 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10443 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10444 | |
| 10445 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10446 | // 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] | 10447 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10448 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10449 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10450 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10451 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10452 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10453 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10454 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10455 | |
| 10456 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10457 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10458 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10459 | } |
| 10460 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10461 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10462 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10463 | HttpRequestInfo request; |
| 10464 | request.method = "GET"; |
| 10465 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10466 | request.traffic_annotation = |
| 10467 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10468 | |
| 10469 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10470 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10471 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10472 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10476 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10480 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10482 | |
| 10483 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10484 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10485 | |
| 10486 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10487 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10488 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10489 | } |
| 10490 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10491 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10492 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10493 | HttpRequestInfo request; |
| 10494 | request.method = "GET"; |
| 10495 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10496 | request.traffic_annotation = |
| 10497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10498 | |
| 10499 | MockRead data_reads[] = { |
| 10500 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10501 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10502 | }; |
| 10503 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10504 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10505 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10507 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10508 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10510 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10512 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10514 | |
| 10515 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10518 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10519 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10520 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10521 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10522 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10523 | |
| 10524 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10525 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10526 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10527 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10528 | |
| 10529 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10530 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10531 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10532 | } |
| 10533 | |
| 10534 | // Make sure that a dropped connection while draining the body for auth |
| 10535 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10536 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10537 | HttpRequestInfo request; |
| 10538 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10539 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10540 | request.traffic_annotation = |
| 10541 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10542 | |
| 10543 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10544 | MockWrite( |
| 10545 | "GET / HTTP/1.1\r\n" |
| 10546 | "Host: www.example.org\r\n" |
| 10547 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10548 | }; |
| 10549 | |
| 10550 | MockRead data_reads1[] = { |
| 10551 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10552 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10553 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10554 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10555 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10556 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10557 | }; |
| 10558 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10559 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10562 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10563 | // be issuing -- the final header line contains the credentials. |
| 10564 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10565 | MockWrite( |
| 10566 | "GET / HTTP/1.1\r\n" |
| 10567 | "Host: www.example.org\r\n" |
| 10568 | "Connection: keep-alive\r\n" |
| 10569 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10570 | }; |
| 10571 | |
| 10572 | // Lastly, the server responds with the actual content. |
| 10573 | MockRead data_reads2[] = { |
| 10574 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10575 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10576 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10578 | }; |
| 10579 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10580 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10581 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10583 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10584 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10586 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10587 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10588 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10590 | |
| 10591 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10595 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10596 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10597 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10598 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10600 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10602 | |
| 10603 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10604 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10606 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10607 | ASSERT_TRUE(response); |
| 10608 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10609 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10610 | } |
| 10611 | |
| 10612 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10613 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10614 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10615 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10616 | |
| 10617 | HttpRequestInfo request; |
| 10618 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10619 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10620 | request.traffic_annotation = |
| 10621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10622 | |
| 10623 | MockRead proxy_reads[] = { |
| 10624 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10625 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10626 | }; |
| 10627 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10628 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10629 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10630 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10631 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10634 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10635 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10636 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10640 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10641 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10643 | |
| 10644 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10645 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10646 | } |
| 10647 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10648 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10649 | HttpRequestInfo request; |
| 10650 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10651 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10652 | request.traffic_annotation = |
| 10653 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10654 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10655 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10656 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10657 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10658 | MockRead data_reads[] = { |
| 10659 | 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] | 10660 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10661 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10662 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10663 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10664 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10666 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10667 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10670 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10671 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10674 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10675 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10676 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10677 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10678 | |
| 10679 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10680 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10681 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10682 | } |
| 10683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10684 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10685 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10686 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10687 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10688 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10689 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10690 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10691 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10692 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10693 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10694 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10695 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10696 | |
| 10697 | HttpRequestInfo request; |
| 10698 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10699 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10700 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10701 | request.traffic_annotation = |
| 10702 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10703 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10706 | |
| 10707 | MockRead data_reads[] = { |
| 10708 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10709 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10711 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10712 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10713 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10715 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10719 | |
| 10720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10721 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10723 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10724 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10725 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10726 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10727 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10728 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10729 | } |
| 10730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10731 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10732 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10733 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10734 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10735 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10736 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10737 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10738 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10739 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10740 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10741 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10742 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10743 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10744 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10745 | |
| 10746 | HttpRequestInfo request; |
| 10747 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10748 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10749 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10750 | request.traffic_annotation = |
| 10751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10752 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10753 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10757 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10758 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10760 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10762 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10764 | |
| 10765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10766 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10767 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10768 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10769 | } |
| 10770 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10771 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10772 | class FakeUploadElementReader : public UploadElementReader { |
| 10773 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10774 | FakeUploadElementReader() = default; |
| 10775 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10776 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10777 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10778 | |
| 10779 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10780 | int Init(CompletionOnceCallback callback) override { |
| 10781 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10782 | return ERR_IO_PENDING; |
| 10783 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10784 | uint64_t GetContentLength() const override { return 0; } |
| 10785 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10786 | int Read(IOBuffer* buf, |
| 10787 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10788 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10789 | return ERR_FAILED; |
| 10790 | } |
| 10791 | |
| 10792 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10793 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10794 | }; |
| 10795 | |
| 10796 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10797 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10798 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10799 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10800 | |
| 10801 | HttpRequestInfo request; |
| 10802 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10803 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10804 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10805 | request.traffic_annotation = |
| 10806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10809 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10810 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10811 | |
| 10812 | StaticSocketDataProvider data; |
| 10813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10814 | |
| 10815 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10816 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10818 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10819 | |
| 10820 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10821 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10822 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10823 | |
| 10824 | // Return Init()'s result after the transaction gets destroyed. |
| 10825 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10826 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10827 | } |
| 10828 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10829 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10830 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10831 | HttpRequestInfo request; |
| 10832 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10833 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10834 | request.traffic_annotation = |
| 10835 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10836 | |
| 10837 | // First transaction will request a resource and receive a Basic challenge |
| 10838 | // with realm="first_realm". |
| 10839 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10840 | MockWrite( |
| 10841 | "GET / HTTP/1.1\r\n" |
| 10842 | "Host: www.example.org\r\n" |
| 10843 | "Connection: keep-alive\r\n" |
| 10844 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10845 | }; |
| 10846 | MockRead data_reads1[] = { |
| 10847 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10848 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10849 | "\r\n"), |
| 10850 | }; |
| 10851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10852 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10853 | // for first_realm. The server will reject and provide a challenge with |
| 10854 | // second_realm. |
| 10855 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10856 | MockWrite( |
| 10857 | "GET / HTTP/1.1\r\n" |
| 10858 | "Host: www.example.org\r\n" |
| 10859 | "Connection: keep-alive\r\n" |
| 10860 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10861 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10862 | }; |
| 10863 | MockRead data_reads2[] = { |
| 10864 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10865 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10866 | "\r\n"), |
| 10867 | }; |
| 10868 | |
| 10869 | // This again fails, and goes back to first_realm. Make sure that the |
| 10870 | // entry is removed from cache. |
| 10871 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10872 | MockWrite( |
| 10873 | "GET / HTTP/1.1\r\n" |
| 10874 | "Host: www.example.org\r\n" |
| 10875 | "Connection: keep-alive\r\n" |
| 10876 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10877 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10878 | }; |
| 10879 | MockRead data_reads3[] = { |
| 10880 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10881 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10882 | "\r\n"), |
| 10883 | }; |
| 10884 | |
| 10885 | // Try one last time (with the correct password) and get the resource. |
| 10886 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10887 | MockWrite( |
| 10888 | "GET / HTTP/1.1\r\n" |
| 10889 | "Host: www.example.org\r\n" |
| 10890 | "Connection: keep-alive\r\n" |
| 10891 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10892 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10893 | }; |
| 10894 | MockRead data_reads4[] = { |
| 10895 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10896 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10897 | "Content-Length: 5\r\n" |
| 10898 | "\r\n" |
| 10899 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10900 | }; |
| 10901 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10902 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10903 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 10904 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 10905 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10906 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10907 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10908 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10909 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10911 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10912 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10913 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10914 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10915 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10916 | // Issue the first request with Authorize headers. There should be a |
| 10917 | // password prompt for first_realm waiting to be filled in after the |
| 10918 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10919 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10921 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10922 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10924 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10925 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10926 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10927 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10928 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10929 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10930 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10931 | |
| 10932 | // Issue the second request with an incorrect password. There should be a |
| 10933 | // password prompt for second_realm waiting to be filled in after the |
| 10934 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10935 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10936 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10937 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10939 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10940 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10941 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10942 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10943 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10944 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10945 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10946 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10947 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10948 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10949 | |
| 10950 | // Issue the third request with another incorrect password. There should be |
| 10951 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10952 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10953 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10954 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10955 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10956 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10958 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10959 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10960 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10961 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10962 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10963 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10964 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10965 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10966 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10967 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10968 | |
| 10969 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10970 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10971 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10972 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10974 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10975 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10976 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10977 | ASSERT_TRUE(response); |
| 10978 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10979 | } |
| 10980 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10981 | // Regression test for https://crbug.com/754395. |
| 10982 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10983 | MockRead data_reads[] = { |
| 10984 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10985 | MockRead(kAlternativeServiceHttpHeader), |
| 10986 | MockRead("\r\n"), |
| 10987 | MockRead("hello world"), |
| 10988 | MockRead(SYNCHRONOUS, OK), |
| 10989 | }; |
| 10990 | |
| 10991 | HttpRequestInfo request; |
| 10992 | request.method = "GET"; |
| 10993 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 10994 | request.traffic_annotation = |
| 10995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10996 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10997 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10999 | |
| 11000 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11001 | ssl.ssl_info.cert = |
| 11002 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11003 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11004 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11006 | |
| 11007 | TestCompletionCallback callback; |
| 11008 | |
| 11009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11011 | |
| 11012 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11014 | |
| 11015 | url::SchemeHostPort test_server(request.url); |
| 11016 | HttpServerProperties* http_server_properties = |
| 11017 | session->http_server_properties(); |
| 11018 | EXPECT_TRUE( |
| 11019 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11020 | |
| 11021 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11022 | |
| 11023 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11024 | ASSERT_TRUE(response); |
| 11025 | ASSERT_TRUE(response->headers); |
| 11026 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11027 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11028 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11029 | |
| 11030 | std::string response_data; |
| 11031 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11032 | EXPECT_EQ("hello world", response_data); |
| 11033 | |
| 11034 | EXPECT_TRUE( |
| 11035 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11036 | } |
| 11037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11038 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11039 | MockRead data_reads[] = { |
| 11040 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11041 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11042 | MockRead("\r\n"), |
| 11043 | MockRead("hello world"), |
| 11044 | MockRead(SYNCHRONOUS, OK), |
| 11045 | }; |
| 11046 | |
| 11047 | HttpRequestInfo request; |
| 11048 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11049 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11050 | request.traffic_annotation = |
| 11051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11052 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11053 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11055 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11056 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11057 | ssl.ssl_info.cert = |
| 11058 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11059 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11061 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11062 | TestCompletionCallback callback; |
| 11063 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11066 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11067 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11069 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11070 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11071 | HttpServerProperties* http_server_properties = |
| 11072 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11073 | EXPECT_TRUE( |
| 11074 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11075 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11076 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11078 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11079 | ASSERT_TRUE(response); |
| 11080 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11081 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11082 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11083 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11084 | |
| 11085 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11086 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11087 | EXPECT_EQ("hello world", response_data); |
| 11088 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11089 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11090 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11091 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11092 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11093 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11094 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11095 | } |
| 11096 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11097 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11098 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11099 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11100 | MockRead data_reads[] = { |
| 11101 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11102 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11103 | MockRead("\r\n"), |
| 11104 | MockRead("hello world"), |
| 11105 | MockRead(SYNCHRONOUS, OK), |
| 11106 | }; |
| 11107 | |
| 11108 | HttpRequestInfo request; |
| 11109 | request.method = "GET"; |
| 11110 | request.url = GURL("http://www.example.org/"); |
| 11111 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11112 | request.traffic_annotation = |
| 11113 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11114 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11115 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11116 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11117 | |
| 11118 | TestCompletionCallback callback; |
| 11119 | |
| 11120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11122 | |
| 11123 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11124 | HttpServerProperties* http_server_properties = |
| 11125 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11126 | EXPECT_TRUE( |
| 11127 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11128 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11129 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11131 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11133 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11134 | ASSERT_TRUE(response); |
| 11135 | ASSERT_TRUE(response->headers); |
| 11136 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11137 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11138 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11139 | |
| 11140 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11141 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11142 | EXPECT_EQ("hello world", response_data); |
| 11143 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11144 | EXPECT_TRUE( |
| 11145 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11146 | } |
| 11147 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11148 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11149 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11150 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11151 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11152 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11153 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11154 | HttpRequestInfo request; |
| 11155 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11156 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11157 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11158 | request.traffic_annotation = |
| 11159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11160 | |
| 11161 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11162 | StaticSocketDataProvider first_data; |
| 11163 | first_data.set_connect_data(mock_connect); |
| 11164 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11165 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11166 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11168 | |
| 11169 | MockRead data_reads[] = { |
| 11170 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11171 | MockRead(ASYNC, OK), |
| 11172 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11173 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11174 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11175 | |
| 11176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11177 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11178 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11179 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11180 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11181 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11182 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11183 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11184 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11187 | TestCompletionCallback callback; |
| 11188 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11189 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11190 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11191 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11192 | } |
| 11193 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11194 | // Regression test for https://crbug.com/615497: |
| 11195 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11196 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11197 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11198 | HttpRequestInfo request; |
| 11199 | request.method = "GET"; |
| 11200 | request.url = GURL("http://www.example.org/"); |
| 11201 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11202 | request.traffic_annotation = |
| 11203 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11204 | |
| 11205 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11206 | StaticSocketDataProvider first_data; |
| 11207 | first_data.set_connect_data(mock_connect); |
| 11208 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11209 | |
| 11210 | MockRead data_reads[] = { |
| 11211 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11212 | MockRead(ASYNC, OK), |
| 11213 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11214 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11215 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11216 | |
| 11217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11218 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11219 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11220 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11221 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11222 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11223 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11224 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11227 | TestCompletionCallback callback; |
| 11228 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11229 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11230 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11231 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11232 | } |
| 11233 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11234 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11235 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11237 | HttpServerProperties* http_server_properties = |
| 11238 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11239 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11240 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11241 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11242 | http_server_properties->SetQuicAlternativeService( |
| 11243 | test_server, alternative_service, expiration, |
| 11244 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11245 | EXPECT_EQ( |
| 11246 | 1u, |
| 11247 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11248 | |
| 11249 | // Send a clear header. |
| 11250 | MockRead data_reads[] = { |
| 11251 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11252 | MockRead("Alt-Svc: clear\r\n"), |
| 11253 | MockRead("\r\n"), |
| 11254 | MockRead("hello world"), |
| 11255 | MockRead(SYNCHRONOUS, OK), |
| 11256 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11257 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11259 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11260 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11261 | ssl.ssl_info.cert = |
| 11262 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11263 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11264 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11265 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11266 | HttpRequestInfo request; |
| 11267 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11268 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11269 | request.traffic_annotation = |
| 11270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11271 | |
| 11272 | TestCompletionCallback callback; |
| 11273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11274 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11275 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11276 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11277 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11279 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11280 | ASSERT_TRUE(response); |
| 11281 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11282 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11283 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11284 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11285 | |
| 11286 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11287 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11288 | EXPECT_EQ("hello world", response_data); |
| 11289 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11290 | EXPECT_TRUE( |
| 11291 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11292 | } |
| 11293 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11294 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11295 | MockRead data_reads[] = { |
| 11296 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11297 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11298 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11299 | MockRead("hello world"), |
| 11300 | MockRead(SYNCHRONOUS, OK), |
| 11301 | }; |
| 11302 | |
| 11303 | HttpRequestInfo request; |
| 11304 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11305 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11306 | request.traffic_annotation = |
| 11307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11308 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11309 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11310 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11311 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11312 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11313 | ssl.ssl_info.cert = |
| 11314 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11315 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11317 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11318 | TestCompletionCallback callback; |
| 11319 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11320 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11321 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11322 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11323 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11325 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11326 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11327 | HttpServerProperties* http_server_properties = |
| 11328 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11329 | EXPECT_TRUE( |
| 11330 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11331 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11332 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11334 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11335 | ASSERT_TRUE(response); |
| 11336 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11337 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11338 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11339 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11340 | |
| 11341 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11342 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11343 | EXPECT_EQ("hello world", response_data); |
| 11344 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11345 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11346 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11347 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11348 | |
| 11349 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11350 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11351 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11352 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11353 | 1234); |
| 11354 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11355 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11356 | } |
| 11357 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11358 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11359 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11360 | HostPortPair alternative("alternative.example.org", 443); |
| 11361 | std::string origin_url = "https://origin.example.org:443"; |
| 11362 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11363 | |
| 11364 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11365 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11366 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11368 | |
| 11369 | // HTTP/1.1 data for request. |
| 11370 | MockWrite http_writes[] = { |
| 11371 | MockWrite("GET / HTTP/1.1\r\n" |
| 11372 | "Host: alternative.example.org\r\n" |
| 11373 | "Connection: keep-alive\r\n\r\n"), |
| 11374 | }; |
| 11375 | |
| 11376 | MockRead http_reads[] = { |
| 11377 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11378 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11379 | "Content-Length: 40\r\n\r\n" |
| 11380 | "first HTTP/1.1 response from alternative"), |
| 11381 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11382 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11383 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11384 | |
| 11385 | StaticSocketDataProvider data_refused; |
| 11386 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11387 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11388 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11389 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11391 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11392 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11393 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11394 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11395 | http_server_properties->SetQuicAlternativeService( |
| 11396 | server, alternative_service, expiration, |
| 11397 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11398 | // Mark the QUIC alternative service as broken. |
| 11399 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11400 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11401 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11403 | request.method = "GET"; |
| 11404 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11405 | request.traffic_annotation = |
| 11406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11407 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11408 | TestCompletionCallback callback; |
| 11409 | NetErrorDetails details; |
| 11410 | EXPECT_FALSE(details.quic_broken); |
| 11411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11412 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11413 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11414 | EXPECT_TRUE(details.quic_broken); |
| 11415 | } |
| 11416 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11417 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11418 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11419 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11420 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11421 | std::string origin_url = "https://origin.example.org:443"; |
| 11422 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11423 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11424 | |
| 11425 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11426 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11427 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11429 | |
| 11430 | // HTTP/1.1 data for request. |
| 11431 | MockWrite http_writes[] = { |
| 11432 | MockWrite("GET / HTTP/1.1\r\n" |
| 11433 | "Host: alternative1.example.org\r\n" |
| 11434 | "Connection: keep-alive\r\n\r\n"), |
| 11435 | }; |
| 11436 | |
| 11437 | MockRead http_reads[] = { |
| 11438 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11439 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11440 | "Content-Length: 40\r\n\r\n" |
| 11441 | "first HTTP/1.1 response from alternative1"), |
| 11442 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11443 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11444 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11445 | |
| 11446 | StaticSocketDataProvider data_refused; |
| 11447 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11448 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11451 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11452 | session->http_server_properties(); |
| 11453 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11454 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11455 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11456 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11457 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11458 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11459 | alternative_service_info_vector.push_back( |
| 11460 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11461 | alternative_service1, expiration, |
| 11462 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11463 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11464 | alternative_service_info_vector.push_back( |
| 11465 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11466 | alternative_service2, expiration, |
| 11467 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11468 | |
| 11469 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11470 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11471 | |
| 11472 | // Mark one of the QUIC alternative service as broken. |
| 11473 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11474 | EXPECT_EQ(2u, |
| 11475 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11476 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11477 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11479 | request.method = "GET"; |
| 11480 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11481 | request.traffic_annotation = |
| 11482 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11483 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11484 | TestCompletionCallback callback; |
| 11485 | NetErrorDetails details; |
| 11486 | EXPECT_FALSE(details.quic_broken); |
| 11487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11488 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11489 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11490 | EXPECT_FALSE(details.quic_broken); |
| 11491 | } |
| 11492 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11493 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11494 | HttpRequestInfo request; |
| 11495 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11496 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11497 | request.traffic_annotation = |
| 11498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11499 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11500 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11501 | StaticSocketDataProvider first_data; |
| 11502 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11503 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11504 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11505 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11507 | |
| 11508 | MockRead data_reads[] = { |
| 11509 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11510 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11511 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11512 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11513 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11514 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11517 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11518 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11519 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11520 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11521 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11522 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11523 | // Port is ignored by MockConnect anyway. |
| 11524 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11525 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11526 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11527 | http_server_properties->SetHttp2AlternativeService( |
| 11528 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11531 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11532 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11533 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11535 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11537 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11538 | ASSERT_TRUE(response); |
| 11539 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11540 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11541 | |
| 11542 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11543 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11544 | EXPECT_EQ("hello world", response_data); |
| 11545 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11546 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11547 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11548 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11549 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11550 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11551 | EXPECT_TRUE( |
| 11552 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11553 | } |
| 11554 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11555 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11556 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11557 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11558 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11559 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11560 | HttpRequestInfo restricted_port_request; |
| 11561 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11562 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11563 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11564 | restricted_port_request.traffic_annotation = |
| 11565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11566 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11567 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11568 | StaticSocketDataProvider first_data; |
| 11569 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11570 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11571 | |
| 11572 | MockRead data_reads[] = { |
| 11573 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11574 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11575 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11576 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11577 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11578 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11579 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11580 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11582 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11584 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11585 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11586 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11587 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11588 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11589 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11590 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11591 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11592 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11593 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11596 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11598 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11599 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11601 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11602 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11603 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11604 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11605 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11606 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11607 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11608 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11609 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11610 | |
| 11611 | HttpRequestInfo restricted_port_request; |
| 11612 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11613 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11614 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11615 | restricted_port_request.traffic_annotation = |
| 11616 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11617 | |
| 11618 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11619 | StaticSocketDataProvider first_data; |
| 11620 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11621 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11622 | |
| 11623 | MockRead data_reads[] = { |
| 11624 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11625 | MockRead("hello world"), |
| 11626 | MockRead(ASYNC, OK), |
| 11627 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11628 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11629 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11630 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11631 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11635 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11636 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11637 | session->http_server_properties(); |
| 11638 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11639 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11640 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11641 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11642 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11643 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11644 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11647 | TestCompletionCallback callback; |
| 11648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11649 | EXPECT_EQ(ERR_IO_PENDING, |
| 11650 | trans.Start(&restricted_port_request, callback.callback(), |
| 11651 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11652 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11653 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11654 | } |
| 11655 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11656 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11657 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11658 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11659 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11660 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11661 | HttpRequestInfo restricted_port_request; |
| 11662 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11663 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11664 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11665 | restricted_port_request.traffic_annotation = |
| 11666 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11667 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11668 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11669 | StaticSocketDataProvider first_data; |
| 11670 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11671 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11672 | |
| 11673 | MockRead data_reads[] = { |
| 11674 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11675 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11676 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11677 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11678 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11679 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11680 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11681 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11683 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11685 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11686 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11687 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11688 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11689 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11690 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11691 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11692 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11693 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11694 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11697 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11699 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11700 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11702 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11703 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11704 | } |
| 11705 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11706 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11707 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11708 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11709 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11710 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11711 | HttpRequestInfo unrestricted_port_request; |
| 11712 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11713 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11714 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11715 | unrestricted_port_request.traffic_annotation = |
| 11716 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11717 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11718 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11719 | StaticSocketDataProvider first_data; |
| 11720 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11721 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11722 | |
| 11723 | MockRead data_reads[] = { |
| 11724 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11725 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11726 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11727 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11728 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11729 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11730 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11731 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11732 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11735 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11736 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11737 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11738 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11739 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11740 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11741 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11742 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11743 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11744 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11747 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11749 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11750 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11752 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11753 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11754 | } |
| 11755 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11756 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11757 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11758 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11759 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11760 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11761 | HttpRequestInfo unrestricted_port_request; |
| 11762 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11763 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11764 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11765 | unrestricted_port_request.traffic_annotation = |
| 11766 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11767 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11768 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11769 | StaticSocketDataProvider first_data; |
| 11770 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11771 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11772 | |
| 11773 | MockRead data_reads[] = { |
| 11774 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11775 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11776 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11777 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11778 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11779 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11780 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11781 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11785 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11786 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11787 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11788 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11789 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11790 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11791 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11792 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11793 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11794 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11797 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11799 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11800 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11802 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11803 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11804 | } |
| 11805 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11806 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 11807 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 11808 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11809 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11810 | HttpRequestInfo request; |
| 11811 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11812 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11813 | request.traffic_annotation = |
| 11814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11815 | |
| 11816 | // The alternate protocol request will error out before we attempt to connect, |
| 11817 | // so only the standard HTTP request will try to connect. |
| 11818 | MockRead data_reads[] = { |
| 11819 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11820 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11821 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11822 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11823 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11824 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11825 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11827 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11828 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11829 | session->http_server_properties(); |
| 11830 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11831 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11832 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11833 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11834 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11835 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11838 | TestCompletionCallback callback; |
| 11839 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11840 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11842 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11843 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11845 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11846 | ASSERT_TRUE(response); |
| 11847 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11848 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11849 | |
| 11850 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11851 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11852 | EXPECT_EQ("hello world", response_data); |
| 11853 | } |
| 11854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11855 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11856 | HttpRequestInfo request; |
| 11857 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11858 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11859 | request.traffic_annotation = |
| 11860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11861 | |
| 11862 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11863 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11864 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11865 | MockRead("\r\n"), |
| 11866 | MockRead("hello world"), |
| 11867 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11868 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11869 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11870 | StaticSocketDataProvider first_transaction(data_reads, |
| 11871 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11872 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11873 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11874 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11876 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11877 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11878 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11879 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11880 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11881 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11882 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11883 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 11884 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11885 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11886 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11887 | }; |
| 11888 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11889 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11890 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11891 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11892 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11893 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11894 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11895 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11896 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11897 | &hanging_non_alternate_protocol_socket); |
| 11898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11899 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11900 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11902 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11903 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11905 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11907 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11908 | |
| 11909 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11910 | ASSERT_TRUE(response); |
| 11911 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11912 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11913 | |
| 11914 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11915 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11916 | EXPECT_EQ("hello world", response_data); |
| 11917 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11918 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11919 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11921 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11923 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11924 | |
| 11925 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11926 | ASSERT_TRUE(response); |
| 11927 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11928 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11929 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11930 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11931 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11932 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11933 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11934 | } |
| 11935 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11936 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11937 | HttpRequestInfo request; |
| 11938 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11939 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 11940 | request.traffic_annotation = |
| 11941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11942 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11943 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11944 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11945 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11946 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11947 | MockRead("\r\n"), |
| 11948 | MockRead("hello world"), |
| 11949 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11950 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11951 | }; |
| 11952 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11953 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11954 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11955 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11956 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11957 | ssl_http11.ssl_info.cert = |
| 11958 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11959 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11960 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11961 | |
| 11962 | // Second transaction starts an alternative and a non-alternative Job. |
| 11963 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11964 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11965 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11966 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11967 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11968 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11969 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11970 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11971 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11972 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11973 | // Third transaction starts an alternative and a non-alternative job. |
| 11974 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11975 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11976 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11977 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11978 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11979 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11980 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11981 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11982 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11983 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 11984 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11985 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 11986 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11987 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11988 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11989 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11990 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11991 | }; |
| 11992 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11993 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11994 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11995 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11996 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11997 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11998 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11999 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12000 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12003 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12004 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12005 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12006 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12008 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12009 | |
| 12010 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12011 | ASSERT_TRUE(response); |
| 12012 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12013 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12014 | |
| 12015 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12016 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12017 | EXPECT_EQ("hello world", response_data); |
| 12018 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12019 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12020 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12021 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12023 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12024 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12025 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12026 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12028 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12029 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12030 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12031 | |
| 12032 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12033 | ASSERT_TRUE(response); |
| 12034 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12035 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12036 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12037 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12038 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12039 | EXPECT_EQ("hello!", response_data); |
| 12040 | |
| 12041 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12042 | ASSERT_TRUE(response); |
| 12043 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12044 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12045 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12046 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12047 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12048 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12049 | } |
| 12050 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12051 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12052 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12053 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12054 | HttpRequestInfo request; |
| 12055 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12056 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12057 | request.traffic_annotation = |
| 12058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12059 | |
| 12060 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12061 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12062 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12063 | MockRead("\r\n"), |
| 12064 | MockRead("hello world"), |
| 12065 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12066 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12067 | }; |
| 12068 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12069 | StaticSocketDataProvider first_transaction(data_reads, |
| 12070 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12071 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12072 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12073 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12074 | ssl.ssl_info.cert = |
| 12075 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12076 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12078 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12079 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12080 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12081 | hanging_alternate_protocol_socket.set_connect_data( |
| 12082 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12083 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12084 | &hanging_alternate_protocol_socket); |
| 12085 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12086 | // 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] | 12087 | StaticSocketDataProvider second_transaction(data_reads, |
| 12088 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12089 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12090 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12091 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12092 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12093 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12095 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12096 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12097 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12098 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12100 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12101 | |
| 12102 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12103 | ASSERT_TRUE(response); |
| 12104 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12105 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12106 | |
| 12107 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12108 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12109 | EXPECT_EQ("hello world", response_data); |
| 12110 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12111 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12112 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12113 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12114 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12116 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12117 | |
| 12118 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12119 | ASSERT_TRUE(response); |
| 12120 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12121 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12122 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12123 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12124 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12125 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12126 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12127 | } |
| 12128 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12129 | class CapturingProxyResolver : public ProxyResolver { |
| 12130 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12131 | CapturingProxyResolver() = default; |
| 12132 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12133 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12134 | int GetProxyForURL(const GURL& url, |
| 12135 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 12136 | CompletionOnceCallback callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12137 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12138 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12139 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12140 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12141 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12142 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12143 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12144 | } |
| 12145 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12146 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12147 | |
| 12148 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12149 | std::vector<GURL> resolved_; |
| 12150 | |
| 12151 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12152 | }; |
| 12153 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12154 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12155 | public: |
| 12156 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12157 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12158 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12159 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12160 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 12161 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12162 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12163 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12164 | return OK; |
| 12165 | } |
| 12166 | |
| 12167 | private: |
| 12168 | ProxyResolver* resolver_; |
| 12169 | }; |
| 12170 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12171 | // Test that proxy is resolved using the origin url, |
| 12172 | // regardless of the alternative server. |
| 12173 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12174 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12175 | ProxyConfig proxy_config; |
| 12176 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12177 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12178 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12179 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12180 | |
| 12181 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12182 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12183 | &capturing_proxy_resolver); |
| 12184 | |
| 12185 | TestNetLog net_log; |
| 12186 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12187 | session_deps_.proxy_resolution_service = |
| 12188 | std::make_unique<ProxyResolutionService>( |
| 12189 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12190 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12191 | |
| 12192 | session_deps_.net_log = &net_log; |
| 12193 | |
| 12194 | // Configure alternative service with a hostname that is not bypassed by the |
| 12195 | // proxy. |
| 12196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12197 | HttpServerProperties* http_server_properties = |
| 12198 | session->http_server_properties(); |
| 12199 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12200 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12201 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12202 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12203 | http_server_properties->SetHttp2AlternativeService( |
| 12204 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12205 | |
| 12206 | // Non-alternative job should hang. |
| 12207 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12208 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12209 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12210 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12211 | &hanging_alternate_protocol_socket); |
| 12212 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12213 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12214 | |
| 12215 | HttpRequestInfo request; |
| 12216 | request.method = "GET"; |
| 12217 | request.url = GURL("https://www.example.org/"); |
| 12218 | request.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12219 | request.traffic_annotation = |
| 12220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12221 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12222 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12223 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12224 | |
| 12225 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12226 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12227 | spdy::SpdySerializedFrame resp( |
| 12228 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12229 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12230 | MockRead spdy_reads[] = { |
| 12231 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12232 | }; |
| 12233 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12234 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12235 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12236 | |
| 12237 | TestCompletionCallback callback; |
| 12238 | |
| 12239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12240 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12241 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12242 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12243 | |
| 12244 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12245 | ASSERT_TRUE(response); |
| 12246 | ASSERT_TRUE(response->headers); |
| 12247 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12248 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12249 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12250 | |
| 12251 | std::string response_data; |
| 12252 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12253 | EXPECT_EQ("hello!", response_data); |
| 12254 | |
| 12255 | // Origin host bypasses proxy, no resolution should have happened. |
| 12256 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12257 | } |
| 12258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12259 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12260 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12261 | proxy_config.set_auto_detect(true); |
| 12262 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12263 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12264 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12265 | session_deps_.proxy_resolution_service = |
| 12266 | std::make_unique<ProxyResolutionService>( |
| 12267 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12268 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12269 | std::make_unique<CapturingProxyResolverFactory>( |
| 12270 | &capturing_proxy_resolver), |
| 12271 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12272 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12273 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12274 | |
| 12275 | HttpRequestInfo request; |
| 12276 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12277 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12278 | request.traffic_annotation = |
| 12279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12280 | |
| 12281 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12282 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12283 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12284 | MockRead("\r\n"), |
| 12285 | MockRead("hello world"), |
| 12286 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12287 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12288 | }; |
| 12289 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12290 | StaticSocketDataProvider first_transaction(data_reads, |
| 12291 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12292 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12293 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12294 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12296 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12297 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12298 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12299 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12300 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12301 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12302 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12303 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12304 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12305 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12306 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12307 | }; |
| 12308 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12309 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12310 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12311 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12312 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12313 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12314 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12315 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12316 | }; |
| 12317 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12318 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12319 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12320 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12321 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12322 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12323 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12324 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12325 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12326 | &hanging_non_alternate_protocol_socket); |
| 12327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12328 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12329 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12330 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12331 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12332 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12333 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12334 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12335 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12336 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12337 | |
| 12338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12339 | ASSERT_TRUE(response); |
| 12340 | ASSERT_TRUE(response->headers); |
| 12341 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12342 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12343 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12344 | |
| 12345 | std::string response_data; |
| 12346 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12347 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12348 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12349 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12350 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12351 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12352 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12354 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12355 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12356 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12357 | ASSERT_TRUE(response); |
| 12358 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12359 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12360 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12361 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12362 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12363 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12364 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12365 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12366 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12367 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12368 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12369 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12370 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12371 | LoadTimingInfo load_timing_info; |
| 12372 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12373 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12374 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12375 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12377 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12378 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12379 | HttpRequestInfo request; |
| 12380 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12381 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 12382 | request.traffic_annotation = |
| 12383 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12384 | |
| 12385 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12386 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12387 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12388 | MockRead("\r\n"), |
| 12389 | MockRead("hello world"), |
| 12390 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12391 | }; |
| 12392 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12393 | StaticSocketDataProvider first_transaction(data_reads, |
| 12394 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12395 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12396 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12397 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12398 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12399 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12400 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12401 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12402 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12403 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12404 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12405 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12406 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12407 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12408 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12409 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12410 | }; |
| 12411 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12412 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12413 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12414 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12415 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12418 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12419 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12420 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12421 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12422 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12424 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12425 | |
| 12426 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12427 | ASSERT_TRUE(response); |
| 12428 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12429 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12430 | |
| 12431 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12432 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12433 | EXPECT_EQ("hello world", response_data); |
| 12434 | |
| 12435 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12436 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12437 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12438 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12439 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12440 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12441 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12442 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12443 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12445 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12447 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12448 | |
| 12449 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12450 | ASSERT_TRUE(response); |
| 12451 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12452 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12453 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12454 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12455 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12456 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12457 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12458 | } |
| 12459 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12460 | // GenerateAuthToken is a mighty big test. |
| 12461 | // It tests all permutation of GenerateAuthToken behavior: |
| 12462 | // - Synchronous and Asynchronous completion. |
| 12463 | // - OK or error on completion. |
| 12464 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12465 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12466 | // - Non-authenticating and authenticating backend. |
| 12467 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12468 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12469 | // problems generating an auth token for an authenticating proxy, we don't |
| 12470 | // need to test all permutations of the backend server). |
| 12471 | // |
| 12472 | // The test proceeds by going over each of the configuration cases, and |
| 12473 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12474 | // specifies both the configuration for the test as well as the expectations |
| 12475 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12476 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12477 | static const char kServer[] = "http://www.example.com"; |
| 12478 | static const char kSecureServer[] = "https://www.example.com"; |
| 12479 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12480 | |
| 12481 | enum AuthTiming { |
| 12482 | AUTH_NONE, |
| 12483 | AUTH_SYNC, |
| 12484 | AUTH_ASYNC, |
| 12485 | }; |
| 12486 | |
| 12487 | const MockWrite kGet( |
| 12488 | "GET / HTTP/1.1\r\n" |
| 12489 | "Host: www.example.com\r\n" |
| 12490 | "Connection: keep-alive\r\n\r\n"); |
| 12491 | const MockWrite kGetProxy( |
| 12492 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12493 | "Host: www.example.com\r\n" |
| 12494 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12495 | const MockWrite kGetAuth( |
| 12496 | "GET / HTTP/1.1\r\n" |
| 12497 | "Host: www.example.com\r\n" |
| 12498 | "Connection: keep-alive\r\n" |
| 12499 | "Authorization: auth_token\r\n\r\n"); |
| 12500 | const MockWrite kGetProxyAuth( |
| 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 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12505 | const MockWrite kGetAuthThroughProxy( |
| 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 | "Authorization: auth_token\r\n\r\n"); |
| 12510 | const MockWrite kGetAuthWithProxyAuth( |
| 12511 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12512 | "Host: www.example.com\r\n" |
| 12513 | "Proxy-Connection: keep-alive\r\n" |
| 12514 | "Proxy-Authorization: auth_token\r\n" |
| 12515 | "Authorization: auth_token\r\n\r\n"); |
| 12516 | const MockWrite kConnect( |
| 12517 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12518 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12519 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12520 | const MockWrite kConnectProxyAuth( |
| 12521 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12522 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12523 | "Proxy-Connection: keep-alive\r\n" |
| 12524 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12525 | |
| 12526 | const MockRead kSuccess( |
| 12527 | "HTTP/1.1 200 OK\r\n" |
| 12528 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12529 | "Content-Length: 3\r\n\r\n" |
| 12530 | "Yes"); |
| 12531 | const MockRead kFailure( |
| 12532 | "Should not be called."); |
| 12533 | const MockRead kServerChallenge( |
| 12534 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12535 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12536 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12537 | "Content-Length: 14\r\n\r\n" |
| 12538 | "Unauthorized\r\n"); |
| 12539 | const MockRead kProxyChallenge( |
| 12540 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12541 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12542 | "Proxy-Connection: close\r\n" |
| 12543 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12544 | "Content-Length: 14\r\n\r\n" |
| 12545 | "Unauthorized\r\n"); |
| 12546 | const MockRead kProxyConnected( |
| 12547 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12548 | |
| 12549 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12550 | // no constructors, but the C++ compiler on Windows warns about |
| 12551 | // unspecified data in compound literals. So, moved to using constructors, |
| 12552 | // and TestRound's created with the default constructor should not be used. |
| 12553 | struct TestRound { |
| 12554 | TestRound() |
| 12555 | : expected_rv(ERR_UNEXPECTED), |
| 12556 | extra_write(NULL), |
| 12557 | extra_read(NULL) { |
| 12558 | } |
| 12559 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12560 | int expected_rv_arg) |
| 12561 | : write(write_arg), |
| 12562 | read(read_arg), |
| 12563 | expected_rv(expected_rv_arg), |
| 12564 | extra_write(NULL), |
| 12565 | extra_read(NULL) { |
| 12566 | } |
| 12567 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12568 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12569 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12570 | : write(write_arg), |
| 12571 | read(read_arg), |
| 12572 | expected_rv(expected_rv_arg), |
| 12573 | extra_write(extra_write_arg), |
| 12574 | extra_read(extra_read_arg) { |
| 12575 | } |
| 12576 | MockWrite write; |
| 12577 | MockRead read; |
| 12578 | int expected_rv; |
| 12579 | const MockWrite* extra_write; |
| 12580 | const MockRead* extra_read; |
| 12581 | }; |
| 12582 | |
| 12583 | static const int kNoSSL = 500; |
| 12584 | |
| 12585 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12586 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12587 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12588 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12589 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12590 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12591 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12592 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12593 | int num_auth_rounds; |
| 12594 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12595 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12596 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12597 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12598 | {__LINE__, |
| 12599 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12600 | AUTH_NONE, |
| 12601 | OK, |
| 12602 | kServer, |
| 12603 | AUTH_NONE, |
| 12604 | OK, |
| 12605 | 1, |
| 12606 | kNoSSL, |
| 12607 | {TestRound(kGet, kSuccess, OK)}}, |
| 12608 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12609 | {__LINE__, |
| 12610 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12611 | AUTH_NONE, |
| 12612 | OK, |
| 12613 | kServer, |
| 12614 | AUTH_SYNC, |
| 12615 | OK, |
| 12616 | 2, |
| 12617 | kNoSSL, |
| 12618 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12619 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12620 | {__LINE__, |
| 12621 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12622 | AUTH_NONE, |
| 12623 | OK, |
| 12624 | kServer, |
| 12625 | AUTH_SYNC, |
| 12626 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12627 | 3, |
| 12628 | kNoSSL, |
| 12629 | {TestRound(kGet, kServerChallenge, OK), |
| 12630 | TestRound(kGet, kServerChallenge, OK), |
| 12631 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12632 | {__LINE__, |
| 12633 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12634 | AUTH_NONE, |
| 12635 | OK, |
| 12636 | kServer, |
| 12637 | AUTH_SYNC, |
| 12638 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12639 | 2, |
| 12640 | kNoSSL, |
| 12641 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12642 | {__LINE__, |
| 12643 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12644 | AUTH_NONE, |
| 12645 | OK, |
| 12646 | kServer, |
| 12647 | AUTH_SYNC, |
| 12648 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12649 | 2, |
| 12650 | kNoSSL, |
| 12651 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12652 | {__LINE__, |
| 12653 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12654 | AUTH_SYNC, |
| 12655 | ERR_FAILED, |
| 12656 | kServer, |
| 12657 | AUTH_NONE, |
| 12658 | OK, |
| 12659 | 2, |
| 12660 | kNoSSL, |
| 12661 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12662 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12663 | {__LINE__, |
| 12664 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12665 | AUTH_ASYNC, |
| 12666 | ERR_FAILED, |
| 12667 | kServer, |
| 12668 | AUTH_NONE, |
| 12669 | OK, |
| 12670 | 2, |
| 12671 | kNoSSL, |
| 12672 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12673 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12674 | {__LINE__, |
| 12675 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12676 | AUTH_NONE, |
| 12677 | OK, |
| 12678 | kServer, |
| 12679 | AUTH_SYNC, |
| 12680 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12681 | 2, |
| 12682 | kNoSSL, |
| 12683 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12684 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12685 | {__LINE__, |
| 12686 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12687 | AUTH_NONE, |
| 12688 | OK, |
| 12689 | kServer, |
| 12690 | AUTH_ASYNC, |
| 12691 | ERR_FAILED, |
| 12692 | 2, |
| 12693 | kNoSSL, |
| 12694 | {TestRound(kGet, kServerChallenge, OK), |
| 12695 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12696 | {__LINE__, |
| 12697 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12698 | AUTH_NONE, |
| 12699 | OK, |
| 12700 | kServer, |
| 12701 | AUTH_ASYNC, |
| 12702 | OK, |
| 12703 | 2, |
| 12704 | kNoSSL, |
| 12705 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12706 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12707 | {__LINE__, |
| 12708 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12709 | AUTH_NONE, |
| 12710 | OK, |
| 12711 | kServer, |
| 12712 | AUTH_ASYNC, |
| 12713 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12714 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12715 | kNoSSL, |
| 12716 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12717 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12718 | TestRound(kGet, kServerChallenge, OK), |
| 12719 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12720 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12721 | {__LINE__, |
| 12722 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12723 | AUTH_NONE, |
| 12724 | OK, |
| 12725 | kServer, |
| 12726 | AUTH_NONE, |
| 12727 | OK, |
| 12728 | 1, |
| 12729 | kNoSSL, |
| 12730 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12731 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12732 | {__LINE__, |
| 12733 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12734 | AUTH_NONE, |
| 12735 | OK, |
| 12736 | kServer, |
| 12737 | AUTH_SYNC, |
| 12738 | OK, |
| 12739 | 2, |
| 12740 | kNoSSL, |
| 12741 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12742 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12743 | {__LINE__, |
| 12744 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12745 | AUTH_NONE, |
| 12746 | OK, |
| 12747 | kServer, |
| 12748 | AUTH_SYNC, |
| 12749 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12750 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12751 | kNoSSL, |
| 12752 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12753 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12754 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12755 | {__LINE__, |
| 12756 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12757 | AUTH_NONE, |
| 12758 | OK, |
| 12759 | kServer, |
| 12760 | AUTH_ASYNC, |
| 12761 | OK, |
| 12762 | 2, |
| 12763 | kNoSSL, |
| 12764 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12765 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12766 | {__LINE__, |
| 12767 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12768 | AUTH_NONE, |
| 12769 | OK, |
| 12770 | kServer, |
| 12771 | AUTH_ASYNC, |
| 12772 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12773 | 2, |
| 12774 | kNoSSL, |
| 12775 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12776 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12777 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12778 | {__LINE__, |
| 12779 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12780 | AUTH_SYNC, |
| 12781 | OK, |
| 12782 | kServer, |
| 12783 | AUTH_NONE, |
| 12784 | OK, |
| 12785 | 2, |
| 12786 | kNoSSL, |
| 12787 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12788 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12789 | {__LINE__, |
| 12790 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12791 | AUTH_SYNC, |
| 12792 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12793 | kServer, |
| 12794 | AUTH_NONE, |
| 12795 | OK, |
| 12796 | 2, |
| 12797 | kNoSSL, |
| 12798 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12799 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12800 | {__LINE__, |
| 12801 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12802 | AUTH_ASYNC, |
| 12803 | OK, |
| 12804 | kServer, |
| 12805 | AUTH_NONE, |
| 12806 | OK, |
| 12807 | 2, |
| 12808 | kNoSSL, |
| 12809 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12810 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12811 | {__LINE__, |
| 12812 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12813 | AUTH_ASYNC, |
| 12814 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12815 | kServer, |
| 12816 | AUTH_NONE, |
| 12817 | OK, |
| 12818 | 2, |
| 12819 | kNoSSL, |
| 12820 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12821 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12822 | {__LINE__, |
| 12823 | kProxy, |
| 12824 | AUTH_ASYNC, |
| 12825 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12826 | kServer, |
| 12827 | AUTH_NONE, |
| 12828 | OK, |
| 12829 | 3, |
| 12830 | kNoSSL, |
| 12831 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12832 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12833 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12834 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12835 | {__LINE__, |
| 12836 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12837 | AUTH_SYNC, |
| 12838 | OK, |
| 12839 | kServer, |
| 12840 | AUTH_SYNC, |
| 12841 | OK, |
| 12842 | 3, |
| 12843 | kNoSSL, |
| 12844 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12845 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12846 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12847 | {__LINE__, |
| 12848 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12849 | AUTH_SYNC, |
| 12850 | OK, |
| 12851 | kServer, |
| 12852 | AUTH_SYNC, |
| 12853 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12854 | 3, |
| 12855 | kNoSSL, |
| 12856 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12857 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12858 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12859 | {__LINE__, |
| 12860 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12861 | AUTH_ASYNC, |
| 12862 | OK, |
| 12863 | kServer, |
| 12864 | AUTH_SYNC, |
| 12865 | OK, |
| 12866 | 3, |
| 12867 | kNoSSL, |
| 12868 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12869 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12870 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12871 | {__LINE__, |
| 12872 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12873 | AUTH_ASYNC, |
| 12874 | OK, |
| 12875 | kServer, |
| 12876 | AUTH_SYNC, |
| 12877 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12878 | 3, |
| 12879 | kNoSSL, |
| 12880 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12881 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12882 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12883 | {__LINE__, |
| 12884 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12885 | AUTH_SYNC, |
| 12886 | OK, |
| 12887 | kServer, |
| 12888 | AUTH_ASYNC, |
| 12889 | OK, |
| 12890 | 3, |
| 12891 | kNoSSL, |
| 12892 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12893 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12894 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12895 | {__LINE__, |
| 12896 | kProxy, |
| 12897 | AUTH_SYNC, |
| 12898 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12899 | kServer, |
| 12900 | AUTH_ASYNC, |
| 12901 | OK, |
| 12902 | 4, |
| 12903 | kNoSSL, |
| 12904 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12905 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12906 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12907 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12908 | {__LINE__, |
| 12909 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12910 | AUTH_SYNC, |
| 12911 | OK, |
| 12912 | kServer, |
| 12913 | AUTH_ASYNC, |
| 12914 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12915 | 3, |
| 12916 | kNoSSL, |
| 12917 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12918 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12919 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12920 | {__LINE__, |
| 12921 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12922 | AUTH_ASYNC, |
| 12923 | OK, |
| 12924 | kServer, |
| 12925 | AUTH_ASYNC, |
| 12926 | OK, |
| 12927 | 3, |
| 12928 | kNoSSL, |
| 12929 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12930 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12931 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12932 | {__LINE__, |
| 12933 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12934 | AUTH_ASYNC, |
| 12935 | OK, |
| 12936 | kServer, |
| 12937 | AUTH_ASYNC, |
| 12938 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12939 | 3, |
| 12940 | kNoSSL, |
| 12941 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12942 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12943 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12944 | {__LINE__, |
| 12945 | kProxy, |
| 12946 | AUTH_ASYNC, |
| 12947 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12948 | kServer, |
| 12949 | AUTH_ASYNC, |
| 12950 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12951 | 4, |
| 12952 | kNoSSL, |
| 12953 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12954 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12955 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12956 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12957 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12958 | {__LINE__, |
| 12959 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12960 | AUTH_NONE, |
| 12961 | OK, |
| 12962 | kSecureServer, |
| 12963 | AUTH_NONE, |
| 12964 | OK, |
| 12965 | 1, |
| 12966 | 0, |
| 12967 | {TestRound(kGet, kSuccess, OK)}}, |
| 12968 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12969 | {__LINE__, |
| 12970 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12971 | AUTH_NONE, |
| 12972 | OK, |
| 12973 | kSecureServer, |
| 12974 | AUTH_SYNC, |
| 12975 | OK, |
| 12976 | 2, |
| 12977 | 0, |
| 12978 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12979 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12980 | {__LINE__, |
| 12981 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12982 | AUTH_NONE, |
| 12983 | OK, |
| 12984 | kSecureServer, |
| 12985 | AUTH_SYNC, |
| 12986 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12987 | 2, |
| 12988 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12989 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12990 | {__LINE__, |
| 12991 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12992 | AUTH_NONE, |
| 12993 | OK, |
| 12994 | kSecureServer, |
| 12995 | AUTH_ASYNC, |
| 12996 | OK, |
| 12997 | 2, |
| 12998 | 0, |
| 12999 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13000 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13001 | {__LINE__, |
| 13002 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13003 | AUTH_NONE, |
| 13004 | OK, |
| 13005 | kSecureServer, |
| 13006 | AUTH_ASYNC, |
| 13007 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13008 | 2, |
| 13009 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13010 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13011 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13012 | {__LINE__, |
| 13013 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13014 | AUTH_NONE, |
| 13015 | OK, |
| 13016 | kSecureServer, |
| 13017 | AUTH_NONE, |
| 13018 | OK, |
| 13019 | 1, |
| 13020 | 0, |
| 13021 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13022 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13023 | {__LINE__, |
| 13024 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13025 | AUTH_NONE, |
| 13026 | OK, |
| 13027 | kSecureServer, |
| 13028 | AUTH_SYNC, |
| 13029 | OK, |
| 13030 | 2, |
| 13031 | 0, |
| 13032 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13033 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13034 | {__LINE__, |
| 13035 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13036 | AUTH_NONE, |
| 13037 | OK, |
| 13038 | kSecureServer, |
| 13039 | AUTH_SYNC, |
| 13040 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13041 | 2, |
| 13042 | 0, |
| 13043 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13044 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13045 | {__LINE__, |
| 13046 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13047 | AUTH_NONE, |
| 13048 | OK, |
| 13049 | kSecureServer, |
| 13050 | AUTH_ASYNC, |
| 13051 | OK, |
| 13052 | 2, |
| 13053 | 0, |
| 13054 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13055 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13056 | {__LINE__, |
| 13057 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13058 | AUTH_NONE, |
| 13059 | OK, |
| 13060 | kSecureServer, |
| 13061 | AUTH_ASYNC, |
| 13062 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13063 | 2, |
| 13064 | 0, |
| 13065 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13066 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13067 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13068 | {__LINE__, |
| 13069 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13070 | AUTH_SYNC, |
| 13071 | OK, |
| 13072 | kSecureServer, |
| 13073 | AUTH_NONE, |
| 13074 | OK, |
| 13075 | 2, |
| 13076 | 1, |
| 13077 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13078 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13079 | {__LINE__, |
| 13080 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13081 | AUTH_SYNC, |
| 13082 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13083 | kSecureServer, |
| 13084 | AUTH_NONE, |
| 13085 | OK, |
| 13086 | 2, |
| 13087 | kNoSSL, |
| 13088 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13089 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13090 | {__LINE__, |
| 13091 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13092 | AUTH_SYNC, |
| 13093 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13094 | kSecureServer, |
| 13095 | AUTH_NONE, |
| 13096 | OK, |
| 13097 | 2, |
| 13098 | kNoSSL, |
| 13099 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13100 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13101 | {__LINE__, |
| 13102 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13103 | AUTH_SYNC, |
| 13104 | ERR_UNEXPECTED, |
| 13105 | kSecureServer, |
| 13106 | AUTH_NONE, |
| 13107 | OK, |
| 13108 | 2, |
| 13109 | kNoSSL, |
| 13110 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13111 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13112 | {__LINE__, |
| 13113 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13114 | AUTH_ASYNC, |
| 13115 | OK, |
| 13116 | kSecureServer, |
| 13117 | AUTH_NONE, |
| 13118 | OK, |
| 13119 | 2, |
| 13120 | 1, |
| 13121 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13122 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13123 | {__LINE__, |
| 13124 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13125 | AUTH_ASYNC, |
| 13126 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13127 | kSecureServer, |
| 13128 | AUTH_NONE, |
| 13129 | OK, |
| 13130 | 2, |
| 13131 | kNoSSL, |
| 13132 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13133 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13134 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13135 | {__LINE__, |
| 13136 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13137 | AUTH_SYNC, |
| 13138 | OK, |
| 13139 | kSecureServer, |
| 13140 | AUTH_SYNC, |
| 13141 | OK, |
| 13142 | 3, |
| 13143 | 1, |
| 13144 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13145 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13146 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13147 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13148 | {__LINE__, |
| 13149 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13150 | AUTH_SYNC, |
| 13151 | OK, |
| 13152 | kSecureServer, |
| 13153 | AUTH_SYNC, |
| 13154 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13155 | 3, |
| 13156 | 1, |
| 13157 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13158 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13159 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13160 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13161 | {__LINE__, |
| 13162 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13163 | AUTH_ASYNC, |
| 13164 | OK, |
| 13165 | kSecureServer, |
| 13166 | AUTH_SYNC, |
| 13167 | OK, |
| 13168 | 3, |
| 13169 | 1, |
| 13170 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13171 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13172 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13173 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13174 | {__LINE__, |
| 13175 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13176 | AUTH_ASYNC, |
| 13177 | OK, |
| 13178 | kSecureServer, |
| 13179 | AUTH_SYNC, |
| 13180 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13181 | 3, |
| 13182 | 1, |
| 13183 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13184 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13185 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13186 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13187 | {__LINE__, |
| 13188 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13189 | AUTH_SYNC, |
| 13190 | OK, |
| 13191 | kSecureServer, |
| 13192 | AUTH_ASYNC, |
| 13193 | OK, |
| 13194 | 3, |
| 13195 | 1, |
| 13196 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13197 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13198 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13199 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13200 | {__LINE__, |
| 13201 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13202 | AUTH_SYNC, |
| 13203 | OK, |
| 13204 | kSecureServer, |
| 13205 | AUTH_ASYNC, |
| 13206 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13207 | 3, |
| 13208 | 1, |
| 13209 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13210 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13211 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13212 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13213 | {__LINE__, |
| 13214 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13215 | AUTH_ASYNC, |
| 13216 | OK, |
| 13217 | kSecureServer, |
| 13218 | AUTH_ASYNC, |
| 13219 | OK, |
| 13220 | 3, |
| 13221 | 1, |
| 13222 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13223 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13224 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13225 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13226 | {__LINE__, |
| 13227 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13228 | AUTH_ASYNC, |
| 13229 | OK, |
| 13230 | kSecureServer, |
| 13231 | AUTH_ASYNC, |
| 13232 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13233 | 3, |
| 13234 | 1, |
| 13235 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13236 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13237 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13238 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13239 | {__LINE__, |
| 13240 | kProxy, |
| 13241 | AUTH_ASYNC, |
| 13242 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13243 | kSecureServer, |
| 13244 | AUTH_ASYNC, |
| 13245 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13246 | 4, |
| 13247 | 2, |
| 13248 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13249 | TestRound(kConnect, kProxyChallenge, OK), |
| 13250 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13251 | &kServerChallenge), |
| 13252 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13253 | }; |
| 13254 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13255 | for (const auto& test_config : test_configs) { |
| 13256 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13257 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13258 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13259 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13260 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13261 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13262 | |
| 13263 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13264 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13265 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13266 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13267 | std::string auth_challenge = "Mock realm=proxy"; |
| 13268 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13269 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13270 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13271 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13272 | empty_ssl_info, origin, |
| 13273 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13274 | auth_handler->SetGenerateExpectation( |
| 13275 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13276 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13277 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13278 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13279 | } |
| 13280 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13281 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13282 | std::string auth_challenge = "Mock realm=server"; |
| 13283 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13284 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13285 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13286 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13287 | empty_ssl_info, origin, |
| 13288 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13289 | auth_handler->SetGenerateExpectation( |
| 13290 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13291 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13292 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13293 | |
| 13294 | // The second handler always succeeds. It should only be used where there |
| 13295 | // are multiple auth sessions for server auth in the same network |
| 13296 | // transaction using the same auth scheme. |
| 13297 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13298 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13299 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13300 | empty_ssl_info, origin, |
| 13301 | NetLogWithSource()); |
| 13302 | second_handler->SetGenerateExpectation(true, OK); |
| 13303 | auth_factory->AddMockHandler(second_handler.release(), |
| 13304 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13305 | } |
| 13306 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13307 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13308 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13309 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13310 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13311 | session_deps_.proxy_resolution_service = |
| 13312 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13313 | } |
| 13314 | |
| 13315 | HttpRequestInfo request; |
| 13316 | request.method = "GET"; |
| 13317 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13318 | request.traffic_annotation = |
| 13319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13322 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13323 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13324 | |
| 13325 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13326 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13327 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13328 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13329 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13330 | |
| 13331 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13332 | mock_reads.back().push_back(read_write_round.read); |
| 13333 | mock_writes.back().push_back(read_write_round.write); |
| 13334 | |
| 13335 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13336 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13337 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13338 | mock_reads.push_back(std::vector<MockRead>()); |
| 13339 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13340 | } |
| 13341 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13342 | if (read_write_round.extra_read) { |
| 13343 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13344 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13345 | if (read_write_round.extra_write) { |
| 13346 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13347 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13348 | |
| 13349 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13350 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13351 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13352 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13353 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13355 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13356 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13357 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13358 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13360 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13361 | } |
| 13362 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13363 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13364 | // they are as well. |
| 13365 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13366 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13367 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13368 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13369 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13370 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13371 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13372 | int rv; |
| 13373 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13374 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13375 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13376 | rv = trans.RestartWithAuth( |
| 13377 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13378 | } |
| 13379 | if (rv == ERR_IO_PENDING) |
| 13380 | rv = callback.WaitForResult(); |
| 13381 | |
| 13382 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13383 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13384 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13385 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13386 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13387 | continue; |
| 13388 | } |
| 13389 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13390 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13391 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13392 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13393 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13394 | } |
| 13395 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13396 | } |
| 13397 | } |
| 13398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13399 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13400 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13401 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13402 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13403 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13404 | session_deps_.proxy_resolution_service = |
| 13405 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13406 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13407 | |
| 13408 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13409 | auth_handler->set_connection_based(true); |
| 13410 | std::string auth_challenge = "Mock realm=server"; |
| 13411 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13412 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13413 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13414 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13415 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13416 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13417 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13418 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13419 | int rv = OK; |
| 13420 | const HttpResponseInfo* response = NULL; |
| 13421 | HttpRequestInfo request; |
| 13422 | request.method = "GET"; |
| 13423 | request.url = origin; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13424 | request.traffic_annotation = |
| 13425 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13428 | |
| 13429 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13430 | // to validate that the TCP socket is not released to the pool between |
| 13431 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13432 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13433 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13434 | 50, // Max sockets for pool |
| 13435 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13436 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13437 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13438 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13439 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13440 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13443 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13444 | |
| 13445 | const MockWrite kGet( |
| 13446 | "GET / HTTP/1.1\r\n" |
| 13447 | "Host: www.example.com\r\n" |
| 13448 | "Connection: keep-alive\r\n\r\n"); |
| 13449 | const MockWrite kGetAuth( |
| 13450 | "GET / HTTP/1.1\r\n" |
| 13451 | "Host: www.example.com\r\n" |
| 13452 | "Connection: keep-alive\r\n" |
| 13453 | "Authorization: auth_token\r\n\r\n"); |
| 13454 | |
| 13455 | const MockRead kServerChallenge( |
| 13456 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13457 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13458 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13459 | "Content-Length: 14\r\n\r\n" |
| 13460 | "Unauthorized\r\n"); |
| 13461 | const MockRead kSuccess( |
| 13462 | "HTTP/1.1 200 OK\r\n" |
| 13463 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13464 | "Content-Length: 3\r\n\r\n" |
| 13465 | "Yes"); |
| 13466 | |
| 13467 | MockWrite writes[] = { |
| 13468 | // First round |
| 13469 | kGet, |
| 13470 | // Second round |
| 13471 | kGetAuth, |
| 13472 | // Third round |
| 13473 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13474 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13475 | kGetAuth, |
| 13476 | // Competing request |
| 13477 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13478 | }; |
| 13479 | MockRead reads[] = { |
| 13480 | // First round |
| 13481 | kServerChallenge, |
| 13482 | // Second round |
| 13483 | kServerChallenge, |
| 13484 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13485 | kServerChallenge, |
| 13486 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13487 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13488 | // Competing response |
| 13489 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13490 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13491 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13492 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13493 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13494 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13495 | |
| 13496 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13497 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13498 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13499 | if (rv == ERR_IO_PENDING) |
| 13500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13501 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13502 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13503 | ASSERT_TRUE(response); |
| 13504 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13505 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13506 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13507 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13508 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13509 | // In between rounds, another request comes in for the same domain. |
| 13510 | // It should not be able to grab the TCP socket that trans has already |
| 13511 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13512 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13513 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13514 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13515 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13517 | // callback_compete.WaitForResult at this point would stall forever, |
| 13518 | // since the HttpNetworkTransaction does not release the request back to |
| 13519 | // the pool until after authentication completes. |
| 13520 | |
| 13521 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13522 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13523 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13524 | if (rv == ERR_IO_PENDING) |
| 13525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13526 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13527 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13528 | ASSERT_TRUE(response); |
| 13529 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13530 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13531 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13532 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13533 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13534 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13535 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13536 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13537 | if (rv == ERR_IO_PENDING) |
| 13538 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13539 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13540 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13541 | ASSERT_TRUE(response); |
| 13542 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13543 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13544 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13545 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13546 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13547 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13548 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13549 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13550 | if (rv == ERR_IO_PENDING) |
| 13551 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13552 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13553 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13554 | ASSERT_TRUE(response); |
| 13555 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13556 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13557 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13558 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13559 | // auth handler should transition to a DONE state in concert with the remote |
| 13560 | // server. But that's not something we can test here with a mock handler. |
| 13561 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13562 | auth_handler->state()); |
| 13563 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13564 | // Read the body since the fourth round was successful. This will also |
| 13565 | // release the socket back to the pool. |
| 13566 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
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 | if (rv == ERR_IO_PENDING) |
| 13569 | rv = callback.WaitForResult(); |
| 13570 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13571 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13572 | EXPECT_EQ(0, rv); |
| 13573 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13574 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13575 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13576 | |
| 13577 | // The competing request can now finish. Wait for the headers and then |
| 13578 | // read the body. |
| 13579 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13580 | EXPECT_THAT(rv, IsOk()); |
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 | if (rv == ERR_IO_PENDING) |
| 13583 | rv = callback.WaitForResult(); |
| 13584 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13585 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13586 | EXPECT_EQ(0, rv); |
| 13587 | |
| 13588 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13589 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13590 | } |
| 13591 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13592 | // This tests the case that a request is issued via http instead of spdy after |
| 13593 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13594 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13595 | HttpRequestInfo request; |
| 13596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13597 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13598 | request.traffic_annotation = |
| 13599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13600 | |
| 13601 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13602 | MockWrite( |
| 13603 | "GET / HTTP/1.1\r\n" |
| 13604 | "Host: www.example.org\r\n" |
| 13605 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13606 | }; |
| 13607 | |
| 13608 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13609 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13610 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13611 | MockRead("\r\n"), |
| 13612 | MockRead("hello world"), |
| 13613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13614 | }; |
| 13615 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13616 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13617 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13618 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13620 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13621 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13624 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13630 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13632 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13635 | ASSERT_TRUE(response); |
| 13636 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13637 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13638 | |
| 13639 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13640 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13641 | EXPECT_EQ("hello world", response_data); |
| 13642 | |
| 13643 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13644 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13645 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13646 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13647 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13648 | // immediate server closing of the socket. |
| 13649 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13650 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13651 | HttpRequestInfo request; |
| 13652 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13653 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13654 | request.traffic_annotation = |
| 13655 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13657 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13658 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13660 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13661 | spdy::SpdySerializedFrame req( |
| 13662 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13663 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13664 | |
| 13665 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13666 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13667 | }; |
| 13668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13669 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13670 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13672 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13676 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13677 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13679 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13680 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13681 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13682 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13683 | // it gets it. This is needed since the auth handler may get destroyed |
| 13684 | // before we get a chance to query it. |
| 13685 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13686 | public: |
| 13687 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13688 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13689 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13690 | |
| 13691 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13692 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13693 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame^] | 13694 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13695 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13696 | *url_ = request->url; |
| 13697 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame^] | 13698 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13699 | } |
| 13700 | |
| 13701 | private: |
| 13702 | GURL* url_; |
| 13703 | }; |
| 13704 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13705 | // Test that if we cancel the transaction as the connection is completing, that |
| 13706 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13707 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13708 | // Setup everything about the connection to complete synchronously, so that |
| 13709 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13710 | // for is the callback from the HttpStreamRequest. |
| 13711 | // Then cancel the transaction. |
| 13712 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13713 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13714 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13715 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13716 | MockRead(SYNCHRONOUS, "hello world"), |
| 13717 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13718 | }; |
| 13719 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13720 | HttpRequestInfo request; |
| 13721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13722 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13723 | request.traffic_annotation = |
| 13724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13727 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13728 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13729 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13730 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13731 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13734 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13735 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13736 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13737 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13739 | trans.reset(); // Cancel the transaction here. |
| 13740 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13741 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13742 | } |
| 13743 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13744 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13745 | // stream is drained properly and added back to the socket pool. The main |
| 13746 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13747 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13748 | // deleted. |
| 13749 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13750 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13751 | MockRead data_reads[] = { |
| 13752 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13753 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13754 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13755 | MockRead(ASYNC, "1"), |
| 13756 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13757 | // HttpNetworkTransaction has been deleted. |
| 13758 | MockRead(ASYNC, "2"), |
| 13759 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13760 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13761 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13765 | |
| 13766 | { |
| 13767 | HttpRequestInfo request; |
| 13768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13769 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13770 | request.traffic_annotation = |
| 13771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13772 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13774 | TestCompletionCallback callback; |
| 13775 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13778 | callback.WaitForResult(); |
| 13779 | |
| 13780 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13781 | ASSERT_TRUE(response); |
| 13782 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13783 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13784 | |
| 13785 | // The transaction and HttpRequestInfo are deleted. |
| 13786 | } |
| 13787 | |
| 13788 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13789 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13790 | |
| 13791 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13792 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13793 | } |
| 13794 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13795 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13796 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13797 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13798 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13799 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13800 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13801 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13803 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13804 | HttpRequestInfo request; |
| 13805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13806 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13807 | request.traffic_annotation = |
| 13808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13809 | |
| 13810 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13811 | MockWrite( |
| 13812 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13813 | "Host: www.example.org\r\n" |
| 13814 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13815 | }; |
| 13816 | |
| 13817 | MockRead data_reads1[] = { |
| 13818 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13819 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13820 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13821 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13822 | }; |
| 13823 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13824 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13825 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13827 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13830 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13831 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13832 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13833 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13835 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13837 | |
| 13838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13839 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13841 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13842 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13843 | |
| 13844 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13845 | EXPECT_EQ(200, response->headers->response_code()); |
| 13846 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13847 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13848 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13849 | HostPortPair::FromString("myproxy:70")), |
| 13850 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13851 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13852 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13853 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13854 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13855 | |
| 13856 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13857 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13858 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13859 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13860 | } |
| 13861 | |
| 13862 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13863 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13864 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13865 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13866 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13867 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13868 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13870 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13871 | HttpRequestInfo request; |
| 13872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13873 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13874 | request.traffic_annotation = |
| 13875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13876 | |
| 13877 | // Since we have proxy, should try to establish tunnel. |
| 13878 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13879 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13880 | "Host: www.example.org:443\r\n" |
| 13881 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13882 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13883 | MockWrite("GET / HTTP/1.1\r\n" |
| 13884 | "Host: www.example.org\r\n" |
| 13885 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13886 | }; |
| 13887 | |
| 13888 | MockRead data_reads1[] = { |
| 13889 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13890 | |
| 13891 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13892 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13893 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13894 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13895 | }; |
| 13896 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13897 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13899 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13902 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13905 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13906 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13907 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13908 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13910 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13912 | |
| 13913 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13914 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13915 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13916 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13917 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13918 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13919 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13920 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13921 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13922 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13923 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13926 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13927 | |
| 13928 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13929 | EXPECT_EQ(200, response->headers->response_code()); |
| 13930 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13931 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13932 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13933 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13934 | HostPortPair::FromString("myproxy:70")), |
| 13935 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13936 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13937 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13938 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13939 | |
| 13940 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13941 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13942 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13943 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13944 | } |
| 13945 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13946 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13947 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13948 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13949 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13950 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13951 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13952 | BoundTestNetLog log; |
| 13953 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13954 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13955 | |
| 13956 | HttpRequestInfo request; |
| 13957 | request.method = "GET"; |
| 13958 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 13959 | request.traffic_annotation = |
| 13960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13961 | |
| 13962 | // Since we have proxy, should try to establish tunnel. |
| 13963 | MockWrite data_writes1[] = { |
| 13964 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13965 | "Host: [::1]:443\r\n" |
| 13966 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13967 | |
| 13968 | MockWrite("GET / HTTP/1.1\r\n" |
| 13969 | "Host: [::1]\r\n" |
| 13970 | "Connection: keep-alive\r\n\r\n"), |
| 13971 | }; |
| 13972 | |
| 13973 | MockRead data_reads1[] = { |
| 13974 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13975 | |
| 13976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13977 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13978 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13979 | MockRead(SYNCHRONOUS, OK), |
| 13980 | }; |
| 13981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13982 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13983 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13984 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13986 | |
| 13987 | TestCompletionCallback callback1; |
| 13988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13991 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13993 | |
| 13994 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13995 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13996 | TestNetLogEntry::List entries; |
| 13997 | log.GetEntries(&entries); |
| 13998 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13999 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14000 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14001 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14002 | entries, pos, |
| 14003 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14004 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14007 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14008 | |
| 14009 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14010 | EXPECT_EQ(200, response->headers->response_code()); |
| 14011 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14013 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14014 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14015 | HostPortPair::FromString("myproxy:70")), |
| 14016 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14017 | |
| 14018 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14019 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14020 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14021 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14022 | } |
| 14023 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14024 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14025 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14026 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14027 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14028 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14029 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14030 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14032 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14033 | HttpRequestInfo request; |
| 14034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14035 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14036 | request.traffic_annotation = |
| 14037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14038 | |
| 14039 | // Since we have proxy, should try to establish tunnel. |
| 14040 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14041 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14042 | "Host: www.example.org:443\r\n" |
| 14043 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14044 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14045 | MockWrite("GET / HTTP/1.1\r\n" |
| 14046 | "Host: www.example.org\r\n" |
| 14047 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14048 | }; |
| 14049 | |
| 14050 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14051 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14052 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14053 | }; |
| 14054 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14055 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14057 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14060 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14064 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14066 | |
| 14067 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14068 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14069 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14070 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14071 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14072 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14073 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14074 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14075 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14076 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14077 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14078 | } |
| 14079 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14080 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14081 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14082 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14083 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14084 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14085 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14086 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14087 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14088 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14089 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14090 | }; |
| 14091 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14092 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14093 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14094 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14095 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14096 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14100 | |
| 14101 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14102 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14103 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14104 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14105 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14106 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14107 | |
| 14108 | HttpRequestInfo request; |
| 14109 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14110 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14111 | request.traffic_annotation = |
| 14112 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14115 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14116 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14117 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14119 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14120 | } |
| 14121 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14122 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14123 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14124 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14125 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14126 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14127 | request_info.url = GURL("https://www.example.com/"); |
| 14128 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14129 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14130 | request_info.traffic_annotation = |
| 14131 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14132 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14133 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14134 | MockWrite data_writes[] = { |
| 14135 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14136 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14137 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14138 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14139 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14144 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14145 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14146 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14147 | rv = callback.WaitForResult(); |
| 14148 | ASSERT_EQ(error, rv); |
| 14149 | } |
| 14150 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14151 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14152 | // Just check a grab bag of cert errors. |
| 14153 | static const int kErrors[] = { |
| 14154 | ERR_CERT_COMMON_NAME_INVALID, |
| 14155 | ERR_CERT_AUTHORITY_INVALID, |
| 14156 | ERR_CERT_DATE_INVALID, |
| 14157 | }; |
| 14158 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14159 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14160 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14161 | } |
| 14162 | } |
| 14163 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14164 | // Ensure that a client certificate is removed from the SSL client auth |
| 14165 | // cache when: |
| 14166 | // 1) No proxy is involved. |
| 14167 | // 2) TLS False Start is disabled. |
| 14168 | // 3) The initial TLS handshake requests a client certificate. |
| 14169 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14170 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14171 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14172 | request_info.url = GURL("https://www.example.com/"); |
| 14173 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14174 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14175 | request_info.traffic_annotation = |
| 14176 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14177 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14178 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14179 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14180 | |
| 14181 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14182 | // CertificateRequest is received for the first time, the handshake will |
| 14183 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14184 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14185 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14187 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14188 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14189 | |
| 14190 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14191 | // False Start is not being used, the result of the SSL handshake will be |
| 14192 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14193 | // matches the result of a server sending a handshake_failure alert, |
| 14194 | // rather than a Finished message, because it requires a client |
| 14195 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14196 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14197 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14199 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14200 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14201 | |
| 14202 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14203 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14204 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14205 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14206 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14207 | // requiring a client certificate, this fallback handshake should also |
| 14208 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14209 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14210 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14212 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14213 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14214 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14215 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14216 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14217 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14218 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14219 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14220 | // requiring a client certificate, this fallback handshake should also |
| 14221 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14222 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14223 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14225 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14226 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14227 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14229 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14230 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14231 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14232 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14233 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14234 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14235 | |
| 14236 | // Complete the SSL handshake, which should abort due to requiring a |
| 14237 | // client certificate. |
| 14238 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14239 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14240 | |
| 14241 | // Indicate that no certificate should be supplied. From the perspective |
| 14242 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14243 | // certificate, so this is the same as supply a |
| 14244 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14245 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14246 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14247 | |
| 14248 | // Ensure the certificate was added to the client auth cache before |
| 14249 | // allowing the connection to continue restarting. |
| 14250 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14251 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14252 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14253 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14254 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14255 | |
| 14256 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14257 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14258 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14259 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14260 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14261 | |
| 14262 | // Ensure that the client certificate is removed from the cache on a |
| 14263 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14264 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14265 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14266 | } |
| 14267 | |
| 14268 | // Ensure that a client certificate is removed from the SSL client auth |
| 14269 | // cache when: |
| 14270 | // 1) No proxy is involved. |
| 14271 | // 2) TLS False Start is enabled. |
| 14272 | // 3) The initial TLS handshake requests a client certificate. |
| 14273 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14274 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14275 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14276 | request_info.url = GURL("https://www.example.com/"); |
| 14277 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14278 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14279 | request_info.traffic_annotation = |
| 14280 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14281 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14282 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14283 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14284 | |
| 14285 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14286 | // return successfully after reading up to the peer's Certificate message. |
| 14287 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14288 | // enqueue application data to be sent in the same packet as the |
| 14289 | // ChangeCipherSpec and Finished messages. |
| 14290 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14291 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14292 | // Finished messages. If there was an error negotiating with the peer, |
| 14293 | // such as due to the peer requiring a client certificate when none was |
| 14294 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14295 | // called. |
| 14296 | |
| 14297 | // Like the non-False Start case, when a client certificate is requested by |
| 14298 | // the peer, the handshake is aborted during the Connect() call. |
| 14299 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14300 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14301 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14302 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14303 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14304 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14305 | |
| 14306 | // When a client certificate is supplied, Connect() will not be aborted |
| 14307 | // when the peer requests the certificate. Instead, the handshake will |
| 14308 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14309 | // the socket. The handshake messages are not processed until Read() is |
| 14310 | // called, which then detects that the handshake was aborted, due to the |
| 14311 | // peer sending a handshake_failure because it requires a client |
| 14312 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14313 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14314 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14316 | MockRead data2_reads[] = { |
| 14317 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14318 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14319 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14320 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14321 | |
| 14322 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14323 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14324 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14325 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14326 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14328 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14329 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14330 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14331 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14332 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14333 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14334 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14336 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14337 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14338 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14339 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14340 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14341 | ssl_data5.cert_request_info = cert_request.get(); |
| 14342 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14343 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14344 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14345 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14346 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14347 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14348 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14349 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14350 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14351 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14352 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14353 | |
| 14354 | // Complete the SSL handshake, which should abort due to requiring a |
| 14355 | // client certificate. |
| 14356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14357 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14358 | |
| 14359 | // Indicate that no certificate should be supplied. From the perspective |
| 14360 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14361 | // certificate, so this is the same as supply a |
| 14362 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14363 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14364 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14365 | |
| 14366 | // Ensure the certificate was added to the client auth cache before |
| 14367 | // allowing the connection to continue restarting. |
| 14368 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14369 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14370 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14371 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14372 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14373 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14374 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14375 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14376 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14377 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14378 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14379 | |
| 14380 | // Ensure that the client certificate is removed from the cache on a |
| 14381 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14382 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14383 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14384 | } |
| 14385 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14386 | // Ensure that a client certificate is removed from the SSL client auth |
| 14387 | // cache when: |
| 14388 | // 1) An HTTPS proxy is involved. |
| 14389 | // 3) The HTTPS proxy requests a client certificate. |
| 14390 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14391 | // proxy. |
| 14392 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14393 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14394 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14395 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14396 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14397 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14398 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14399 | |
| 14400 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14401 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14402 | |
| 14403 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14404 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14405 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14406 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14407 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14408 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14409 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14410 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14412 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14413 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14414 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14416 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14417 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14418 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14419 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14420 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14421 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14422 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14424 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14425 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14426 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14427 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14428 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14429 | requests[0].url = GURL("https://www.example.com/"); |
| 14430 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14431 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14432 | requests[0].traffic_annotation = |
| 14433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14434 | |
| 14435 | requests[1].url = GURL("http://www.example.com/"); |
| 14436 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14437 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14438 | requests[1].traffic_annotation = |
| 14439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14440 | |
| 14441 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14442 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14445 | |
| 14446 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14447 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14448 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14449 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14450 | |
| 14451 | // Complete the SSL handshake, which should abort due to requiring a |
| 14452 | // client certificate. |
| 14453 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14454 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14455 | |
| 14456 | // Indicate that no certificate should be supplied. From the perspective |
| 14457 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14458 | // certificate, so this is the same as supply a |
| 14459 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14460 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14461 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14462 | |
| 14463 | // Ensure the certificate was added to the client auth cache before |
| 14464 | // allowing the connection to continue restarting. |
| 14465 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14466 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14467 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14468 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14469 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14470 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14471 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14472 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14473 | HostPortPair("www.example.com", 443), &client_cert, |
| 14474 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14475 | |
| 14476 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14477 | // then consume ssl_data3, which should also fail. The result code is |
| 14478 | // checked against what ssl_data3 should return. |
| 14479 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14480 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14481 | |
| 14482 | // Now that the new handshake has failed, ensure that the client |
| 14483 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14484 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14485 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14486 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14487 | HostPortPair("www.example.com", 443), &client_cert, |
| 14488 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14489 | } |
| 14490 | } |
| 14491 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14492 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14493 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14494 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14496 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14497 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14498 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14499 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14500 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14501 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14502 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14503 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14504 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14505 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14506 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14507 | spdy::SpdySerializedFrame host1_resp( |
| 14508 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14509 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14510 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14511 | spdy::SpdySerializedFrame host2_resp( |
| 14512 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14513 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14514 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14515 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14516 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14517 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14518 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14519 | }; |
| 14520 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14521 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14522 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14523 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14524 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14525 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14526 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14527 | HttpRequestInfo request1; |
| 14528 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14529 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14530 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14531 | request1.traffic_annotation = |
| 14532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14533 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14534 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14535 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14536 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14537 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14538 | |
| 14539 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14540 | ASSERT_TRUE(response); |
| 14541 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14542 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14543 | |
| 14544 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14545 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14546 | EXPECT_EQ("hello!", response_data); |
| 14547 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14548 | // Preload mail.example.com into HostCache. |
| 14549 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14550 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14551 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14552 | std::unique_ptr<HostResolver::Request> request; |
| 14553 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14554 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14555 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14557 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14558 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14559 | |
| 14560 | HttpRequestInfo request2; |
| 14561 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14562 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14563 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14564 | request2.traffic_annotation = |
| 14565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14566 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14568 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14569 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14570 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14571 | |
| 14572 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14573 | ASSERT_TRUE(response); |
| 14574 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14575 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14576 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14577 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14578 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14579 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14580 | } |
| 14581 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14582 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14583 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14584 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14586 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14587 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14588 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14589 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14590 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14591 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14592 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14593 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14594 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14595 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14596 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14597 | spdy::SpdySerializedFrame host1_resp( |
| 14598 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14599 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14600 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14601 | spdy::SpdySerializedFrame host2_resp( |
| 14602 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14603 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14604 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14605 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14606 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14607 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14608 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14609 | }; |
| 14610 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14611 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14612 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14613 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14614 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14615 | |
| 14616 | TestCompletionCallback callback; |
| 14617 | HttpRequestInfo request1; |
| 14618 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14619 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14620 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14621 | request1.traffic_annotation = |
| 14622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14623 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14625 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14627 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14628 | |
| 14629 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14630 | ASSERT_TRUE(response); |
| 14631 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14632 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14633 | |
| 14634 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14635 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14636 | EXPECT_EQ("hello!", response_data); |
| 14637 | |
| 14638 | HttpRequestInfo request2; |
| 14639 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14640 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14641 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14642 | request2.traffic_annotation = |
| 14643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14644 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14646 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14648 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14649 | |
| 14650 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14651 | ASSERT_TRUE(response); |
| 14652 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14653 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14654 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14655 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14656 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14657 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14658 | } |
| 14659 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14660 | // Regression test for https://crbug.com/546991. |
| 14661 | // The server might not be able to serve an IP pooled request, and might send a |
| 14662 | // 421 Misdirected Request response status to indicate this. |
| 14663 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14664 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14665 | // Two hosts resolve to the same IP address. |
| 14666 | const std::string ip_addr = "1.2.3.4"; |
| 14667 | IPAddress ip; |
| 14668 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14669 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14670 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14671 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14672 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14673 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14674 | |
| 14675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14676 | |
| 14677 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14678 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14679 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14680 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14681 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14682 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14683 | spdy::SpdySerializedFrame rst( |
| 14684 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14685 | MockWrite writes1[] = { |
| 14686 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14687 | CreateMockWrite(rst, 6), |
| 14688 | }; |
| 14689 | |
| 14690 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14691 | spdy::SpdySerializedFrame resp1( |
| 14692 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14693 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14694 | spdy::SpdyHeaderBlock response_headers; |
| 14695 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14696 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14697 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14698 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14699 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14700 | |
| 14701 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14702 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14703 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14704 | |
| 14705 | AddSSLSocketData(); |
| 14706 | |
| 14707 | // Retry the second request on a second connection. |
| 14708 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14709 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14710 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14711 | MockWrite writes2[] = { |
| 14712 | CreateMockWrite(req3, 0), |
| 14713 | }; |
| 14714 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14715 | spdy::SpdySerializedFrame resp3( |
| 14716 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14717 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14718 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14719 | MockRead(ASYNC, 0, 3)}; |
| 14720 | |
| 14721 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14722 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14723 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14724 | |
| 14725 | AddSSLSocketData(); |
| 14726 | |
| 14727 | // Preload mail.example.org into HostCache. |
| 14728 | HostPortPair host_port("mail.example.org", 443); |
| 14729 | HostResolver::RequestInfo resolve_info(host_port); |
| 14730 | AddressList ignored; |
| 14731 | std::unique_ptr<HostResolver::Request> request; |
| 14732 | TestCompletionCallback callback; |
| 14733 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14734 | &ignored, callback.callback(), |
| 14735 | &request, NetLogWithSource()); |
| 14736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14737 | rv = callback.WaitForResult(); |
| 14738 | EXPECT_THAT(rv, IsOk()); |
| 14739 | |
| 14740 | HttpRequestInfo request1; |
| 14741 | request1.method = "GET"; |
| 14742 | request1.url = GURL("https://www.example.org/"); |
| 14743 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14744 | request1.traffic_annotation = |
| 14745 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14746 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14747 | |
| 14748 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14750 | rv = callback.WaitForResult(); |
| 14751 | EXPECT_THAT(rv, IsOk()); |
| 14752 | |
| 14753 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14754 | ASSERT_TRUE(response); |
| 14755 | ASSERT_TRUE(response->headers); |
| 14756 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14757 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14758 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14759 | std::string response_data; |
| 14760 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14761 | EXPECT_EQ("hello!", response_data); |
| 14762 | |
| 14763 | HttpRequestInfo request2; |
| 14764 | request2.method = "GET"; |
| 14765 | request2.url = GURL("https://mail.example.org/"); |
| 14766 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14767 | request2.traffic_annotation = |
| 14768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14769 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14770 | |
| 14771 | BoundTestNetLog log; |
| 14772 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14774 | rv = callback.WaitForResult(); |
| 14775 | EXPECT_THAT(rv, IsOk()); |
| 14776 | |
| 14777 | response = trans2.GetResponseInfo(); |
| 14778 | ASSERT_TRUE(response); |
| 14779 | ASSERT_TRUE(response->headers); |
| 14780 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14781 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14782 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14783 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14784 | EXPECT_EQ("hello!", response_data); |
| 14785 | |
| 14786 | TestNetLogEntry::List entries; |
| 14787 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14788 | ExpectLogContainsSomewhere( |
| 14789 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14790 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14791 | } |
| 14792 | |
| 14793 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14794 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14795 | // portions of the response. |
| 14796 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14797 | // Two hosts resolve to the same IP address. |
| 14798 | const std::string ip_addr = "1.2.3.4"; |
| 14799 | IPAddress ip; |
| 14800 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14801 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14802 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14803 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14804 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14805 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14806 | |
| 14807 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14808 | |
| 14809 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14810 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14811 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14812 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14813 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14814 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14815 | spdy::SpdySerializedFrame rst( |
| 14816 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14817 | MockWrite writes1[] = { |
| 14818 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14819 | CreateMockWrite(rst, 6), |
| 14820 | }; |
| 14821 | |
| 14822 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14823 | spdy::SpdySerializedFrame resp1( |
| 14824 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14825 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14826 | spdy::SpdyHeaderBlock response_headers; |
| 14827 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14828 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14829 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14830 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14831 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14832 | |
| 14833 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14834 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14835 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14836 | |
| 14837 | AddSSLSocketData(); |
| 14838 | |
| 14839 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14840 | // Retry again. |
| 14841 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14842 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14843 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14844 | MockWrite writes2[] = { |
| 14845 | CreateMockWrite(req3, 0), |
| 14846 | }; |
| 14847 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14848 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14849 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14850 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14851 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14852 | MockRead(ASYNC, 0, 3)}; |
| 14853 | |
| 14854 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14855 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14856 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14857 | |
| 14858 | AddSSLSocketData(); |
| 14859 | |
| 14860 | // Preload mail.example.org into HostCache. |
| 14861 | HostPortPair host_port("mail.example.org", 443); |
| 14862 | HostResolver::RequestInfo resolve_info(host_port); |
| 14863 | AddressList ignored; |
| 14864 | std::unique_ptr<HostResolver::Request> request; |
| 14865 | TestCompletionCallback callback; |
| 14866 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14867 | &ignored, callback.callback(), |
| 14868 | &request, NetLogWithSource()); |
| 14869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14870 | rv = callback.WaitForResult(); |
| 14871 | EXPECT_THAT(rv, IsOk()); |
| 14872 | |
| 14873 | HttpRequestInfo request1; |
| 14874 | request1.method = "GET"; |
| 14875 | request1.url = GURL("https://www.example.org/"); |
| 14876 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14877 | request1.traffic_annotation = |
| 14878 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14879 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14880 | |
| 14881 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14883 | rv = callback.WaitForResult(); |
| 14884 | EXPECT_THAT(rv, IsOk()); |
| 14885 | |
| 14886 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14887 | ASSERT_TRUE(response); |
| 14888 | ASSERT_TRUE(response->headers); |
| 14889 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14890 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14891 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14892 | std::string response_data; |
| 14893 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14894 | EXPECT_EQ("hello!", response_data); |
| 14895 | |
| 14896 | HttpRequestInfo request2; |
| 14897 | request2.method = "GET"; |
| 14898 | request2.url = GURL("https://mail.example.org/"); |
| 14899 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14900 | request2.traffic_annotation = |
| 14901 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14902 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14903 | |
| 14904 | BoundTestNetLog log; |
| 14905 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14907 | rv = callback.WaitForResult(); |
| 14908 | EXPECT_THAT(rv, IsOk()); |
| 14909 | |
| 14910 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14911 | // caller. |
| 14912 | response = trans2.GetResponseInfo(); |
| 14913 | ASSERT_TRUE(response); |
| 14914 | ASSERT_TRUE(response->headers); |
| 14915 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14916 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14917 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14918 | EXPECT_TRUE(response->ssl_info.cert); |
| 14919 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14920 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14921 | } |
| 14922 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14923 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14924 | public: |
| 14925 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14926 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14927 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14928 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14929 | int ResolveFromCache(const RequestInfo& info, |
| 14930 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14931 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14932 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14933 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14934 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14935 | return rv; |
| 14936 | } |
| 14937 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14938 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14939 | const HostPortPair host_port_; |
| 14940 | }; |
| 14941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14942 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14943 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14944 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14945 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14946 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14948 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14949 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14950 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14951 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14952 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14953 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14954 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14955 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14956 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14957 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14958 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14959 | spdy::SpdySerializedFrame host1_resp( |
| 14960 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14961 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14962 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14963 | spdy::SpdySerializedFrame host2_resp( |
| 14964 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14965 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14966 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14967 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14968 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14969 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14970 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14971 | }; |
| 14972 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14973 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14974 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14975 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14976 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14977 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14978 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14979 | HttpRequestInfo request1; |
| 14980 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14981 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14982 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 14983 | request1.traffic_annotation = |
| 14984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14985 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14986 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14987 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14989 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14990 | |
| 14991 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14992 | ASSERT_TRUE(response); |
| 14993 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14994 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14995 | |
| 14996 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14997 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14998 | EXPECT_EQ("hello!", response_data); |
| 14999 | |
| 15000 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15001 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15002 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15003 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15004 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15005 | &ignored, callback.callback(), |
| 15006 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15008 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15010 | |
| 15011 | HttpRequestInfo request2; |
| 15012 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15013 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15014 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15015 | request2.traffic_annotation = |
| 15016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15017 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15019 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15021 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15022 | |
| 15023 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15024 | ASSERT_TRUE(response); |
| 15025 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15026 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15027 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15028 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15029 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15030 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15031 | } |
| 15032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15033 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15034 | const std::string https_url = "https://www.example.org:8080/"; |
| 15035 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15036 | |
| 15037 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15038 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15039 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15040 | |
| 15041 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15042 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15043 | }; |
| 15044 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15045 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15046 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15047 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15048 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15049 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15050 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15051 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15052 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15053 | |
| 15054 | // HTTP GET for the HTTP URL |
| 15055 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15056 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15057 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15058 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15059 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15060 | }; |
| 15061 | |
| 15062 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15063 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15064 | MockRead(ASYNC, 2, "hello"), |
| 15065 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15066 | }; |
| 15067 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15068 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15069 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15070 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15071 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15074 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15077 | |
| 15078 | // Start the first transaction to set up the SpdySession |
| 15079 | HttpRequestInfo request1; |
| 15080 | request1.method = "GET"; |
| 15081 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15082 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15083 | request1.traffic_annotation = |
| 15084 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15085 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15086 | TestCompletionCallback callback1; |
| 15087 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15088 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15089 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15090 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15091 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15092 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15093 | |
| 15094 | // Now, start the HTTP request |
| 15095 | HttpRequestInfo request2; |
| 15096 | request2.method = "GET"; |
| 15097 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15098 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15099 | request2.traffic_annotation = |
| 15100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15101 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15102 | TestCompletionCallback callback2; |
| 15103 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15104 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15105 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15106 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15107 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15108 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15109 | } |
| 15110 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15111 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15112 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15113 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15114 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15115 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15116 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15117 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15118 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15119 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15121 | |
| 15122 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15123 | // negotiated. |
| 15124 | StaticSocketDataProvider data; |
| 15125 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15126 | |
| 15127 | // 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] | 15128 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15129 | // mocked. This way the request relies on the alternate Job. |
| 15130 | StaticSocketDataProvider data_refused; |
| 15131 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15132 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15133 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15134 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15136 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15137 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15138 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15139 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15140 | http_server_properties->SetHttp2AlternativeService( |
| 15141 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15142 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15143 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15145 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15146 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15147 | request.traffic_annotation = |
| 15148 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15149 | TestCompletionCallback callback; |
| 15150 | |
| 15151 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15152 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15154 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15155 | } |
| 15156 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15157 | // 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] | 15158 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15159 | // succeeds, the request should succeed, even if the latter fails because |
| 15160 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15161 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15162 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15163 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15164 | |
| 15165 | // Negotiate HTTP/1.1 with alternative. |
| 15166 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15167 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15169 | |
| 15170 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15171 | // negotiated. |
| 15172 | StaticSocketDataProvider data; |
| 15173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15174 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15175 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15176 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15177 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15179 | |
| 15180 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15181 | MockWrite("GET / HTTP/1.1\r\n" |
| 15182 | "Host: www.example.org\r\n" |
| 15183 | "Connection: keep-alive\r\n\r\n"), |
| 15184 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15185 | "Host: www.example.org\r\n" |
| 15186 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15187 | }; |
| 15188 | |
| 15189 | MockRead http_reads[] = { |
| 15190 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15191 | MockRead("Content-Type: text/html\r\n"), |
| 15192 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15193 | MockRead("foobar"), |
| 15194 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15195 | MockRead("Content-Type: text/html\r\n"), |
| 15196 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15197 | MockRead("another"), |
| 15198 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15199 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15200 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15201 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15202 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15204 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15205 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15206 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15207 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15208 | http_server_properties->SetHttp2AlternativeService( |
| 15209 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15210 | |
| 15211 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15212 | HttpRequestInfo request1; |
| 15213 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15214 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15215 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15216 | request1.traffic_annotation = |
| 15217 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15218 | TestCompletionCallback callback1; |
| 15219 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15220 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15221 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15222 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15223 | |
| 15224 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15225 | ASSERT_TRUE(response1); |
| 15226 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15227 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15228 | |
| 15229 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15230 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15231 | EXPECT_EQ("foobar", response_data1); |
| 15232 | |
| 15233 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15234 | // for alternative service. |
| 15235 | EXPECT_TRUE( |
| 15236 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15237 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15238 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15239 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15240 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15241 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15242 | HttpRequestInfo request2; |
| 15243 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15244 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15245 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15246 | request2.traffic_annotation = |
| 15247 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15248 | TestCompletionCallback callback2; |
| 15249 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15250 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15251 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15252 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15253 | |
| 15254 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15255 | ASSERT_TRUE(response2); |
| 15256 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15257 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15258 | |
| 15259 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15260 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15261 | EXPECT_EQ("another", response_data2); |
| 15262 | } |
| 15263 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15264 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15265 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15266 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15267 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15268 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15269 | HostPortPair alternative("alternative.example.org", 443); |
| 15270 | std::string origin_url = "https://origin.example.org:443"; |
| 15271 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15272 | |
| 15273 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15274 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15275 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15277 | |
| 15278 | // HTTP/1.1 data for |request1| and |request2|. |
| 15279 | MockWrite http_writes[] = { |
| 15280 | MockWrite( |
| 15281 | "GET / HTTP/1.1\r\n" |
| 15282 | "Host: alternative.example.org\r\n" |
| 15283 | "Connection: keep-alive\r\n\r\n"), |
| 15284 | MockWrite( |
| 15285 | "GET / HTTP/1.1\r\n" |
| 15286 | "Host: alternative.example.org\r\n" |
| 15287 | "Connection: keep-alive\r\n\r\n"), |
| 15288 | }; |
| 15289 | |
| 15290 | MockRead http_reads[] = { |
| 15291 | MockRead( |
| 15292 | "HTTP/1.1 200 OK\r\n" |
| 15293 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15294 | "Content-Length: 40\r\n\r\n" |
| 15295 | "first HTTP/1.1 response from alternative"), |
| 15296 | MockRead( |
| 15297 | "HTTP/1.1 200 OK\r\n" |
| 15298 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15299 | "Content-Length: 41\r\n\r\n" |
| 15300 | "second HTTP/1.1 response from alternative"), |
| 15301 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15302 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15303 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15304 | |
| 15305 | // This test documents that an alternate Job should not pool to an already |
| 15306 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15307 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15308 | StaticSocketDataProvider data_refused; |
| 15309 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15310 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15311 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15312 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15313 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15314 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15315 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15316 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15317 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15318 | http_server_properties->SetHttp2AlternativeService( |
| 15319 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15320 | |
| 15321 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15322 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15323 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15324 | request1.method = "GET"; |
| 15325 | request1.url = GURL(alternative_url); |
| 15326 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15327 | request1.traffic_annotation = |
| 15328 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15329 | TestCompletionCallback callback1; |
| 15330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15331 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15332 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15333 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15334 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15335 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15336 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15337 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15338 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15339 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15340 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15341 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15342 | |
| 15343 | // Request for origin.example.org, which has an alternative service. This |
| 15344 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15345 | // 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] | 15346 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15347 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15348 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15349 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15350 | request2.method = "GET"; |
| 15351 | request2.url = GURL(origin_url); |
| 15352 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15353 | request2.traffic_annotation = |
| 15354 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15355 | TestCompletionCallback callback2; |
| 15356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15357 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15358 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15359 | |
| 15360 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15361 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15362 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15363 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15364 | request3.method = "GET"; |
| 15365 | request3.url = GURL(alternative_url); |
| 15366 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15367 | request3.traffic_annotation = |
| 15368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15369 | TestCompletionCallback callback3; |
| 15370 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15371 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15372 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15373 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15374 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15375 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15376 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15377 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15378 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15379 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15380 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15381 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15382 | } |
| 15383 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15384 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15385 | const std::string https_url = "https://www.example.org:8080/"; |
| 15386 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15387 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15388 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15389 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15390 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15391 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15392 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15393 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15394 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15395 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15396 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15397 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15398 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15399 | |
| 15400 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15401 | spdy::SpdyHeaderBlock req2_block; |
| 15402 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 15403 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15404 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 15405 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 15406 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15407 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15408 | |
| 15409 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15410 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15411 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15412 | }; |
| 15413 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15414 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15415 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15416 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15417 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15418 | spdy::SpdySerializedFrame body1( |
| 15419 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15420 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15421 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15422 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15423 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15424 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15425 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15426 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15427 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15428 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15429 | CreateMockRead(wrapped_resp1, 4), |
| 15430 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15431 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15432 | CreateMockRead(resp2, 8), |
| 15433 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15434 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15435 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15436 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15437 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15438 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15439 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15440 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15441 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15442 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15443 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15444 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15445 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15446 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15447 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15449 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15450 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15451 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15452 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15453 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15454 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15455 | |
| 15456 | // Start the first transaction to set up the SpdySession |
| 15457 | HttpRequestInfo request1; |
| 15458 | request1.method = "GET"; |
| 15459 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15460 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15461 | request1.traffic_annotation = |
| 15462 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15463 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15464 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15465 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15466 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15467 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15468 | data1.RunUntilPaused(); |
| 15469 | base::RunLoop().RunUntilIdle(); |
| 15470 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15471 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15472 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15473 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15474 | LoadTimingInfo load_timing_info1; |
| 15475 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15476 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15477 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15478 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15479 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15480 | HttpRequestInfo request2; |
| 15481 | request2.method = "GET"; |
| 15482 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15483 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15484 | request2.traffic_annotation = |
| 15485 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15486 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15487 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15488 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15489 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15490 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15491 | data1.RunUntilPaused(); |
| 15492 | base::RunLoop().RunUntilIdle(); |
| 15493 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15494 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15495 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15496 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15497 | |
| 15498 | LoadTimingInfo load_timing_info2; |
| 15499 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15500 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15501 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15502 | // HTTP requests over a SPDY session should have a different connection |
| 15503 | // socket_log_id than requests over a tunnel. |
| 15504 | 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] | 15505 | } |
| 15506 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15507 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15508 | // that we do not pool other origins that resolve to the same IP when |
| 15509 | // the certificate does not match the new origin. |
| 15510 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15511 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15512 | const std::string url1 = "http://www.example.org/"; |
| 15513 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15514 | const std::string ip_addr = "1.2.3.4"; |
| 15515 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15516 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15517 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15518 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15519 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15520 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15521 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15522 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15523 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15524 | |
| 15525 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15526 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15527 | }; |
| 15528 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15529 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15530 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15531 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15532 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15533 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15534 | }; |
| 15535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15536 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15537 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15538 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15539 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15540 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15541 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15542 | |
| 15543 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15544 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15545 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15546 | |
| 15547 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15548 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15549 | }; |
| 15550 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15551 | spdy::SpdySerializedFrame resp2( |
| 15552 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15553 | spdy::SpdySerializedFrame body2( |
| 15554 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15555 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15556 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15557 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15558 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15559 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15560 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15561 | |
| 15562 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15563 | // all others direct. |
| 15564 | ProxyConfig proxy_config; |
| 15565 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15566 | session_deps_.proxy_resolution_service = |
| 15567 | std::make_unique<ProxyResolutionService>( |
| 15568 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15569 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15570 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15571 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15572 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15573 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15574 | // Load a valid cert. Note, that this does not need to |
| 15575 | // be valid for proxy because the MockSSLClientSocket does |
| 15576 | // not actually verify it. But SpdySession will use this |
| 15577 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15578 | ssl1.ssl_info.cert = |
| 15579 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15580 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15582 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15583 | |
| 15584 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15585 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15586 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15587 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15588 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15589 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15590 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15591 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15593 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15594 | |
| 15595 | // Start the first transaction to set up the SpdySession |
| 15596 | HttpRequestInfo request1; |
| 15597 | request1.method = "GET"; |
| 15598 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15599 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15600 | request1.traffic_annotation = |
| 15601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15602 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15603 | TestCompletionCallback callback1; |
| 15604 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15605 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15606 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15607 | data1.RunUntilPaused(); |
| 15608 | base::RunLoop().RunUntilIdle(); |
| 15609 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15610 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15611 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15612 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15613 | |
| 15614 | // Now, start the HTTP request |
| 15615 | HttpRequestInfo request2; |
| 15616 | request2.method = "GET"; |
| 15617 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15618 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15619 | request2.traffic_annotation = |
| 15620 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15621 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15622 | TestCompletionCallback callback2; |
| 15623 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15624 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15625 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15626 | |
| 15627 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15628 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15629 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15630 | } |
| 15631 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15632 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15633 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15634 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15635 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15636 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15637 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15638 | |
| 15639 | MockRead reads1[] = { |
| 15640 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15641 | }; |
| 15642 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15643 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15644 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15645 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15646 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15647 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15648 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15649 | }; |
| 15650 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15651 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15652 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15653 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15654 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15655 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15656 | }; |
| 15657 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15658 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15659 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15660 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15661 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15663 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15664 | |
| 15665 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15666 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15668 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15670 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15671 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15672 | |
| 15673 | // Start the first transaction to set up the SpdySession and verify that |
| 15674 | // connection was closed. |
| 15675 | HttpRequestInfo request1; |
| 15676 | request1.method = "GET"; |
| 15677 | request1.url = GURL(https_url); |
| 15678 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15679 | request1.traffic_annotation = |
| 15680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15681 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15682 | TestCompletionCallback callback1; |
| 15683 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15684 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15685 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15686 | |
| 15687 | // Now, start the second request and make sure it succeeds. |
| 15688 | HttpRequestInfo request2; |
| 15689 | request2.method = "GET"; |
| 15690 | request2.url = GURL(https_url); |
| 15691 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15692 | request2.traffic_annotation = |
| 15693 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15694 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15695 | TestCompletionCallback callback2; |
| 15696 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15697 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15698 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15699 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15700 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15701 | } |
| 15702 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15703 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15704 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15705 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15706 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15707 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15708 | |
| 15709 | // Use two different hosts with different IPs so they don't get pooled. |
| 15710 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15711 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15713 | |
| 15714 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15715 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15716 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15717 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15719 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15720 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15721 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15722 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15723 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15724 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15725 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15726 | spdy::SpdySerializedFrame host1_resp( |
| 15727 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15728 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15729 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15730 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15731 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15732 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15733 | }; |
| 15734 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15735 | // Use a separate test instance for the separate SpdySession that will be |
| 15736 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15737 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15738 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15739 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15740 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15741 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15742 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15743 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15744 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15745 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15746 | spdy::SpdySerializedFrame host2_resp( |
| 15747 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15748 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15749 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15750 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15751 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15752 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15753 | }; |
| 15754 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15755 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15756 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15757 | |
| 15758 | MockWrite http_write[] = { |
| 15759 | MockWrite("GET / HTTP/1.1\r\n" |
| 15760 | "Host: www.a.com\r\n" |
| 15761 | "Connection: keep-alive\r\n\r\n"), |
| 15762 | }; |
| 15763 | |
| 15764 | MockRead http_read[] = { |
| 15765 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15766 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15767 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15768 | MockRead("hello!"), |
| 15769 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15770 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15771 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15772 | |
| 15773 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15774 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15775 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15776 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15777 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15778 | |
| 15779 | TestCompletionCallback callback; |
| 15780 | HttpRequestInfo request1; |
| 15781 | request1.method = "GET"; |
| 15782 | request1.url = GURL("https://www.a.com/"); |
| 15783 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15784 | request1.traffic_annotation = |
| 15785 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15786 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15787 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15788 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15789 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15791 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15792 | |
| 15793 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15794 | ASSERT_TRUE(response); |
| 15795 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15796 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15797 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15798 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15799 | |
| 15800 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15801 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15802 | EXPECT_EQ("hello!", response_data); |
| 15803 | trans.reset(); |
| 15804 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15805 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15806 | |
| 15807 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15808 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15809 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15810 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15811 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15812 | HttpRequestInfo request2; |
| 15813 | request2.method = "GET"; |
| 15814 | request2.url = GURL("https://www.b.com/"); |
| 15815 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15816 | request2.traffic_annotation = |
| 15817 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15818 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15819 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15821 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15823 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15824 | |
| 15825 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15826 | ASSERT_TRUE(response); |
| 15827 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15828 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15829 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15830 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15831 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15832 | EXPECT_EQ("hello!", response_data); |
| 15833 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15834 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15835 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15836 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15837 | |
| 15838 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15839 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15840 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15841 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15842 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15843 | HttpRequestInfo request3; |
| 15844 | request3.method = "GET"; |
| 15845 | request3.url = GURL("http://www.a.com/"); |
| 15846 | request3.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15847 | request3.traffic_annotation = |
| 15848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15849 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15852 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15854 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15855 | |
| 15856 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15857 | ASSERT_TRUE(response); |
| 15858 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15859 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15860 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15861 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15862 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15863 | EXPECT_EQ("hello!", response_data); |
| 15864 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15865 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15866 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15867 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15868 | } |
| 15869 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15870 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15871 | HttpRequestInfo request; |
| 15872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15873 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15874 | request.traffic_annotation = |
| 15875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15879 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15880 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15881 | StaticSocketDataProvider data; |
| 15882 | data.set_connect_data(mock_connect); |
| 15883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15884 | |
| 15885 | TestCompletionCallback callback; |
| 15886 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15887 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15889 | |
| 15890 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15891 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15892 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15893 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15894 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15895 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15896 | |
| 15897 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15898 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15899 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15900 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15901 | |
| 15902 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15903 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15904 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15905 | } |
| 15906 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15907 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15908 | HttpRequestInfo request; |
| 15909 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15910 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15911 | request.traffic_annotation = |
| 15912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15916 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15917 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15918 | StaticSocketDataProvider data; |
| 15919 | data.set_connect_data(mock_connect); |
| 15920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15921 | |
| 15922 | TestCompletionCallback callback; |
| 15923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15926 | |
| 15927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15928 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15929 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15930 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15931 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15932 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15933 | |
| 15934 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15935 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15936 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15937 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15938 | |
| 15939 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15940 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15941 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15942 | } |
| 15943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15944 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15945 | HttpRequestInfo request; |
| 15946 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15947 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15948 | request.traffic_annotation = |
| 15949 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15950 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15953 | |
| 15954 | MockWrite data_writes[] = { |
| 15955 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15956 | }; |
| 15957 | MockRead data_reads[] = { |
| 15958 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15959 | }; |
| 15960 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15961 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15963 | |
| 15964 | TestCompletionCallback callback; |
| 15965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15966 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15967 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15968 | |
| 15969 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15970 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15971 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15972 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15973 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15974 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15975 | } |
| 15976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15977 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15978 | HttpRequestInfo request; |
| 15979 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15980 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 15981 | request.traffic_annotation = |
| 15982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15983 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15986 | |
| 15987 | MockWrite data_writes[] = { |
| 15988 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15989 | }; |
| 15990 | MockRead data_reads[] = { |
| 15991 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15992 | }; |
| 15993 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15994 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15996 | |
| 15997 | TestCompletionCallback callback; |
| 15998 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15999 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16001 | |
| 16002 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16003 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16004 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16005 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16006 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16007 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16008 | } |
| 16009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16010 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16011 | HttpRequestInfo request; |
| 16012 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16013 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16014 | request.traffic_annotation = |
| 16015 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16019 | |
| 16020 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16021 | MockWrite( |
| 16022 | "GET / HTTP/1.1\r\n" |
| 16023 | "Host: www.example.org\r\n" |
| 16024 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16025 | }; |
| 16026 | MockRead data_reads[] = { |
| 16027 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16028 | }; |
| 16029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16030 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16032 | |
| 16033 | TestCompletionCallback callback; |
| 16034 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16035 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16037 | |
| 16038 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16039 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16040 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16041 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16042 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16043 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16044 | } |
| 16045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16046 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16047 | HttpRequestInfo request; |
| 16048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16049 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16050 | request.traffic_annotation = |
| 16051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16052 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16054 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16055 | |
| 16056 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16057 | MockWrite( |
| 16058 | "GET / HTTP/1.1\r\n" |
| 16059 | "Host: www.example.org\r\n" |
| 16060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16061 | }; |
| 16062 | MockRead data_reads[] = { |
| 16063 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16064 | }; |
| 16065 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16066 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16068 | |
| 16069 | TestCompletionCallback callback; |
| 16070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16071 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16073 | |
| 16074 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16075 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16076 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16077 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16078 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16079 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16080 | } |
| 16081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16082 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16083 | HttpRequestInfo request; |
| 16084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16085 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16086 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16087 | request.traffic_annotation = |
| 16088 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16092 | |
| 16093 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16094 | MockWrite( |
| 16095 | "GET / HTTP/1.1\r\n" |
| 16096 | "Host: www.example.org\r\n" |
| 16097 | "Connection: keep-alive\r\n" |
| 16098 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16099 | }; |
| 16100 | MockRead data_reads[] = { |
| 16101 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16102 | "Content-Length: 5\r\n\r\n" |
| 16103 | "hello"), |
| 16104 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16105 | }; |
| 16106 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16107 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16109 | |
| 16110 | TestCompletionCallback callback; |
| 16111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16112 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16114 | |
| 16115 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16117 | |
| 16118 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16119 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16120 | std::string foo; |
| 16121 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16122 | EXPECT_EQ("bar", foo); |
| 16123 | } |
| 16124 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16125 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16126 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16127 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16128 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16129 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16130 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16131 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16132 | |
| 16133 | // Set up SSL request. |
| 16134 | |
| 16135 | HttpRequestInfo ssl_request; |
| 16136 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16137 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16138 | ssl_request.traffic_annotation = |
| 16139 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16140 | |
| 16141 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16142 | MockWrite( |
| 16143 | "GET / HTTP/1.1\r\n" |
| 16144 | "Host: www.example.org\r\n" |
| 16145 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16146 | }; |
| 16147 | MockRead ssl_reads[] = { |
| 16148 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16149 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16150 | MockRead("hello world"), |
| 16151 | MockRead(SYNCHRONOUS, OK), |
| 16152 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16153 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16154 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16155 | |
| 16156 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16157 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16158 | |
| 16159 | // Set up HTTP request. |
| 16160 | |
| 16161 | HttpRequestInfo http_request; |
| 16162 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16163 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16164 | http_request.traffic_annotation = |
| 16165 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16166 | |
| 16167 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16168 | MockWrite( |
| 16169 | "GET / HTTP/1.1\r\n" |
| 16170 | "Host: www.example.org\r\n" |
| 16171 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16172 | }; |
| 16173 | MockRead http_reads[] = { |
| 16174 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16175 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16176 | MockRead("falafel"), |
| 16177 | MockRead(SYNCHRONOUS, OK), |
| 16178 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16179 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16180 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16181 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16183 | |
| 16184 | // Start the SSL request. |
| 16185 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16186 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16187 | ASSERT_EQ(ERR_IO_PENDING, |
| 16188 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16189 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16190 | |
| 16191 | // Start the HTTP request. Pool should stall. |
| 16192 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16193 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16194 | ASSERT_EQ(ERR_IO_PENDING, |
| 16195 | http_trans.Start(&http_request, http_callback.callback(), |
| 16196 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16197 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16198 | |
| 16199 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16200 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16201 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16202 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16203 | EXPECT_EQ("hello world", response_data); |
| 16204 | |
| 16205 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16206 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16207 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16208 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16209 | |
| 16210 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16211 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16212 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16213 | EXPECT_EQ("falafel", response_data); |
| 16214 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16215 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16216 | } |
| 16217 | |
| 16218 | // Tests that when a SSL connection is established but there's no corresponding |
| 16219 | // request that needs it, the new socket is closed if the transport socket pool |
| 16220 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16221 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16222 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16223 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16224 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16225 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16226 | |
| 16227 | // Set up an ssl request. |
| 16228 | |
| 16229 | HttpRequestInfo ssl_request; |
| 16230 | ssl_request.method = "GET"; |
| 16231 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16232 | ssl_request.traffic_annotation = |
| 16233 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16234 | |
| 16235 | // No data will be sent on the SSL socket. |
| 16236 | StaticSocketDataProvider ssl_data; |
| 16237 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16238 | |
| 16239 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16241 | |
| 16242 | // Set up HTTP request. |
| 16243 | |
| 16244 | HttpRequestInfo http_request; |
| 16245 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16246 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16247 | http_request.traffic_annotation = |
| 16248 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16249 | |
| 16250 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16251 | MockWrite( |
| 16252 | "GET / HTTP/1.1\r\n" |
| 16253 | "Host: www.example.org\r\n" |
| 16254 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16255 | }; |
| 16256 | MockRead http_reads[] = { |
| 16257 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16258 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16259 | MockRead("falafel"), |
| 16260 | MockRead(SYNCHRONOUS, OK), |
| 16261 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16262 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16263 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16264 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16266 | |
| 16267 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16268 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16269 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16270 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16271 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16272 | |
| 16273 | // Start the HTTP request. Pool should stall. |
| 16274 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16275 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16276 | ASSERT_EQ(ERR_IO_PENDING, |
| 16277 | http_trans.Start(&http_request, http_callback.callback(), |
| 16278 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16279 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16280 | |
| 16281 | // The SSL connection will automatically be closed once the connection is |
| 16282 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16283 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16284 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16285 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16286 | EXPECT_EQ("falafel", response_data); |
| 16287 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16288 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16289 | } |
| 16290 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16291 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16292 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16293 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16294 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16295 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16296 | |
| 16297 | HttpRequestInfo request; |
| 16298 | request.method = "POST"; |
| 16299 | request.url = GURL("http://www.foo.com/"); |
| 16300 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16301 | request.traffic_annotation = |
| 16302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16303 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16306 | // Send headers successfully, but get an error while sending the body. |
| 16307 | MockWrite data_writes[] = { |
| 16308 | MockWrite("POST / HTTP/1.1\r\n" |
| 16309 | "Host: www.foo.com\r\n" |
| 16310 | "Connection: keep-alive\r\n" |
| 16311 | "Content-Length: 3\r\n\r\n"), |
| 16312 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16313 | }; |
| 16314 | |
| 16315 | MockRead data_reads[] = { |
| 16316 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16317 | MockRead("hello world"), |
| 16318 | MockRead(SYNCHRONOUS, OK), |
| 16319 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16320 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16321 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16322 | |
| 16323 | TestCompletionCallback callback; |
| 16324 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16325 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16326 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16327 | |
| 16328 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16329 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16331 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16332 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16333 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16334 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16335 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16336 | |
| 16337 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16338 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16339 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16340 | EXPECT_EQ("hello world", response_data); |
| 16341 | } |
| 16342 | |
| 16343 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16344 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16345 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16346 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16348 | MockWrite data_writes[] = { |
| 16349 | MockWrite("GET / HTTP/1.1\r\n" |
| 16350 | "Host: www.foo.com\r\n" |
| 16351 | "Connection: keep-alive\r\n\r\n"), |
| 16352 | MockWrite("POST / HTTP/1.1\r\n" |
| 16353 | "Host: www.foo.com\r\n" |
| 16354 | "Connection: keep-alive\r\n" |
| 16355 | "Content-Length: 3\r\n\r\n"), |
| 16356 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16357 | }; |
| 16358 | |
| 16359 | MockRead data_reads[] = { |
| 16360 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16361 | "Content-Length: 14\r\n\r\n"), |
| 16362 | MockRead("first response"), |
| 16363 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16364 | "Content-Length: 15\r\n\r\n"), |
| 16365 | MockRead("second response"), |
| 16366 | MockRead(SYNCHRONOUS, OK), |
| 16367 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16368 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16370 | |
| 16371 | TestCompletionCallback callback; |
| 16372 | HttpRequestInfo request1; |
| 16373 | request1.method = "GET"; |
| 16374 | request1.url = GURL("http://www.foo.com/"); |
| 16375 | request1.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16376 | request1.traffic_annotation = |
| 16377 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16378 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16379 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16380 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16381 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16383 | |
| 16384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16386 | |
| 16387 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16388 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16389 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16390 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16391 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16392 | |
| 16393 | std::string response_data1; |
| 16394 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16395 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16396 | EXPECT_EQ("first response", response_data1); |
| 16397 | // Delete the transaction to release the socket back into the socket pool. |
| 16398 | trans1.reset(); |
| 16399 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16400 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16401 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16402 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16403 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16404 | |
| 16405 | HttpRequestInfo request2; |
| 16406 | request2.method = "POST"; |
| 16407 | request2.url = GURL("http://www.foo.com/"); |
| 16408 | request2.upload_data_stream = &upload_data_stream; |
| 16409 | request2.load_flags = 0; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16410 | request2.traffic_annotation = |
| 16411 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16413 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16414 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16416 | |
| 16417 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16418 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16420 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16421 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16422 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16423 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16424 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16425 | |
| 16426 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16427 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16429 | EXPECT_EQ("second response", response_data2); |
| 16430 | } |
| 16431 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16432 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16433 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16434 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16435 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16436 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16437 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16438 | |
| 16439 | HttpRequestInfo request; |
| 16440 | request.method = "POST"; |
| 16441 | request.url = GURL("http://www.foo.com/"); |
| 16442 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16443 | request.traffic_annotation = |
| 16444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16445 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16448 | // Send headers successfully, but get an error while sending the body. |
| 16449 | MockWrite data_writes[] = { |
| 16450 | MockWrite("POST / HTTP/1.1\r\n" |
| 16451 | "Host: www.foo.com\r\n" |
| 16452 | "Connection: keep-alive\r\n" |
| 16453 | "Content-Length: 3\r\n\r\n" |
| 16454 | "fo"), |
| 16455 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16456 | }; |
| 16457 | |
| 16458 | MockRead data_reads[] = { |
| 16459 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16460 | MockRead("hello world"), |
| 16461 | MockRead(SYNCHRONOUS, OK), |
| 16462 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16463 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16464 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16465 | |
| 16466 | TestCompletionCallback callback; |
| 16467 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16468 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16470 | |
| 16471 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16475 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16476 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16477 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16478 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16479 | |
| 16480 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16481 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16483 | EXPECT_EQ("hello world", response_data); |
| 16484 | } |
| 16485 | |
| 16486 | // This tests the more common case than the previous test, where headers and |
| 16487 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16488 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16489 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16490 | |
| 16491 | HttpRequestInfo request; |
| 16492 | request.method = "POST"; |
| 16493 | request.url = GURL("http://www.foo.com/"); |
| 16494 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16495 | request.traffic_annotation = |
| 16496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16500 | // Send headers successfully, but get an error while sending the body. |
| 16501 | MockWrite data_writes[] = { |
| 16502 | MockWrite("POST / HTTP/1.1\r\n" |
| 16503 | "Host: www.foo.com\r\n" |
| 16504 | "Connection: keep-alive\r\n" |
| 16505 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16506 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16507 | }; |
| 16508 | |
| 16509 | MockRead data_reads[] = { |
| 16510 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16511 | MockRead("hello world"), |
| 16512 | MockRead(SYNCHRONOUS, OK), |
| 16513 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16514 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16515 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16516 | |
| 16517 | TestCompletionCallback callback; |
| 16518 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16519 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16521 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16522 | // they can't be merged with the body in a single send. Not currently |
| 16523 | // necessary since a chunked body is never merged with headers, but this makes |
| 16524 | // the test more future proof. |
| 16525 | base::RunLoop().RunUntilIdle(); |
| 16526 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16527 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16528 | |
| 16529 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16530 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16532 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16533 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16534 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16535 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16536 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16537 | |
| 16538 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16539 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16540 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16541 | EXPECT_EQ("hello world", response_data); |
| 16542 | } |
| 16543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16544 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16545 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16546 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16547 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16548 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16549 | |
| 16550 | HttpRequestInfo request; |
| 16551 | request.method = "POST"; |
| 16552 | request.url = GURL("http://www.foo.com/"); |
| 16553 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16554 | request.traffic_annotation = |
| 16555 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16559 | |
| 16560 | MockWrite data_writes[] = { |
| 16561 | MockWrite("POST / HTTP/1.1\r\n" |
| 16562 | "Host: www.foo.com\r\n" |
| 16563 | "Connection: keep-alive\r\n" |
| 16564 | "Content-Length: 3\r\n\r\n"), |
| 16565 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16566 | }; |
| 16567 | |
| 16568 | MockRead data_reads[] = { |
| 16569 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16570 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16571 | MockRead("hello world"), |
| 16572 | MockRead(SYNCHRONOUS, OK), |
| 16573 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16574 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16576 | |
| 16577 | TestCompletionCallback callback; |
| 16578 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16579 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16581 | |
| 16582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16584 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16585 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16586 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16587 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16588 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16589 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16590 | |
| 16591 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16592 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16594 | EXPECT_EQ("hello world", response_data); |
| 16595 | } |
| 16596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16597 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16598 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16599 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16600 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16601 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16602 | |
| 16603 | HttpRequestInfo request; |
| 16604 | request.method = "POST"; |
| 16605 | request.url = GURL("http://www.foo.com/"); |
| 16606 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16607 | request.traffic_annotation = |
| 16608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16612 | // Send headers successfully, but get an error while sending the body. |
| 16613 | MockWrite data_writes[] = { |
| 16614 | MockWrite("POST / HTTP/1.1\r\n" |
| 16615 | "Host: www.foo.com\r\n" |
| 16616 | "Connection: keep-alive\r\n" |
| 16617 | "Content-Length: 3\r\n\r\n"), |
| 16618 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16619 | }; |
| 16620 | |
| 16621 | MockRead data_reads[] = { |
| 16622 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16623 | MockRead("hello world"), |
| 16624 | MockRead(SYNCHRONOUS, OK), |
| 16625 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16626 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16628 | |
| 16629 | TestCompletionCallback callback; |
| 16630 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16631 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16633 | |
| 16634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16635 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16636 | } |
| 16637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16638 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16639 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16640 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16641 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16642 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16643 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16644 | |
| 16645 | HttpRequestInfo request; |
| 16646 | request.method = "POST"; |
| 16647 | request.url = GURL("http://www.foo.com/"); |
| 16648 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16649 | request.traffic_annotation = |
| 16650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16651 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16652 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16653 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16654 | // Send headers successfully, but get an error while sending the body. |
| 16655 | MockWrite data_writes[] = { |
| 16656 | MockWrite("POST / HTTP/1.1\r\n" |
| 16657 | "Host: www.foo.com\r\n" |
| 16658 | "Connection: keep-alive\r\n" |
| 16659 | "Content-Length: 3\r\n\r\n"), |
| 16660 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16661 | }; |
| 16662 | |
| 16663 | MockRead data_reads[] = { |
| 16664 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16665 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16666 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16667 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16668 | MockRead(SYNCHRONOUS, OK), |
| 16669 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16670 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16671 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16672 | |
| 16673 | TestCompletionCallback callback; |
| 16674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16675 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16676 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16677 | |
| 16678 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16679 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16680 | } |
| 16681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16682 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16683 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16684 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16685 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16686 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16687 | |
| 16688 | HttpRequestInfo request; |
| 16689 | request.method = "POST"; |
| 16690 | request.url = GURL("http://www.foo.com/"); |
| 16691 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16692 | request.traffic_annotation = |
| 16693 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16697 | // Send headers successfully, but get an error while sending the body. |
| 16698 | MockWrite data_writes[] = { |
| 16699 | MockWrite("POST / HTTP/1.1\r\n" |
| 16700 | "Host: www.foo.com\r\n" |
| 16701 | "Connection: keep-alive\r\n" |
| 16702 | "Content-Length: 3\r\n\r\n"), |
| 16703 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16704 | }; |
| 16705 | |
| 16706 | MockRead data_reads[] = { |
| 16707 | MockRead("HTTP 0.9 rocks!"), |
| 16708 | MockRead(SYNCHRONOUS, OK), |
| 16709 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16710 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16712 | |
| 16713 | TestCompletionCallback callback; |
| 16714 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16715 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16717 | |
| 16718 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16719 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16720 | } |
| 16721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16722 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16723 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16724 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16725 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16726 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16727 | |
| 16728 | HttpRequestInfo request; |
| 16729 | request.method = "POST"; |
| 16730 | request.url = GURL("http://www.foo.com/"); |
| 16731 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16732 | request.traffic_annotation = |
| 16733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16737 | // Send headers successfully, but get an error while sending the body. |
| 16738 | MockWrite data_writes[] = { |
| 16739 | MockWrite("POST / HTTP/1.1\r\n" |
| 16740 | "Host: www.foo.com\r\n" |
| 16741 | "Connection: keep-alive\r\n" |
| 16742 | "Content-Length: 3\r\n\r\n"), |
| 16743 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16744 | }; |
| 16745 | |
| 16746 | MockRead data_reads[] = { |
| 16747 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16748 | MockRead(SYNCHRONOUS, OK), |
| 16749 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16750 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16752 | |
| 16753 | TestCompletionCallback callback; |
| 16754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16757 | |
| 16758 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16759 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16760 | } |
| 16761 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16762 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 16763 | |
| 16764 | namespace { |
| 16765 | |
| 16766 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 16767 | headers->SetHeader("Connection", "Upgrade"); |
| 16768 | headers->SetHeader("Upgrade", "websocket"); |
| 16769 | headers->SetHeader("Origin", "http://www.example.org"); |
| 16770 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16771 | } |
| 16772 | |
| 16773 | } // namespace |
| 16774 | |
| 16775 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16776 | for (bool secure : {true, false}) { |
| 16777 | MockWrite data_writes[] = { |
| 16778 | MockWrite("GET / HTTP/1.1\r\n" |
| 16779 | "Host: www.example.org\r\n" |
| 16780 | "Connection: Upgrade\r\n" |
| 16781 | "Upgrade: websocket\r\n" |
| 16782 | "Origin: http://www.example.org\r\n" |
| 16783 | "Sec-WebSocket-Version: 13\r\n" |
| 16784 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16785 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16786 | "client_max_window_bits\r\n\r\n")}; |
| 16787 | |
| 16788 | MockRead data_reads[] = { |
| 16789 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16790 | "Upgrade: websocket\r\n" |
| 16791 | "Connection: Upgrade\r\n" |
| 16792 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 16793 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16794 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16795 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16796 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16797 | if (secure) |
| 16798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16799 | |
| 16800 | HttpRequestInfo request; |
| 16801 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16802 | request.url = |
| 16803 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 16804 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16805 | request.traffic_annotation = |
| 16806 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16807 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16808 | TestWebSocketHandshakeStreamCreateHelper |
| 16809 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16810 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16812 | HttpNetworkTransaction trans(LOW, session.get()); |
| 16813 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16814 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16815 | |
| 16816 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16819 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16820 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 16821 | ASSERT_TRUE(stream_request); |
| 16822 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 16823 | stream_request->websocket_handshake_stream_create_helper()); |
| 16824 | |
| 16825 | rv = callback.WaitForResult(); |
| 16826 | EXPECT_THAT(rv, IsOk()); |
| 16827 | |
| 16828 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 16829 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16830 | } |
| 16831 | } |
| 16832 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16833 | // Verify that proxy headers are not sent to the destination server when |
| 16834 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16835 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16836 | HttpRequestInfo request; |
| 16837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16838 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16839 | request.traffic_annotation = |
| 16840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16841 | AddWebSocketHeaders(&request.extra_headers); |
| 16842 | |
| 16843 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16844 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16845 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16846 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16849 | |
| 16850 | // Since a proxy is configured, try to establish a tunnel. |
| 16851 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16852 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16853 | "Host: www.example.org:443\r\n" |
| 16854 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16855 | |
| 16856 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16857 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16858 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16859 | "Host: www.example.org:443\r\n" |
| 16860 | "Proxy-Connection: keep-alive\r\n" |
| 16861 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16862 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16863 | MockWrite("GET / HTTP/1.1\r\n" |
| 16864 | "Host: www.example.org\r\n" |
| 16865 | "Connection: Upgrade\r\n" |
| 16866 | "Upgrade: websocket\r\n" |
| 16867 | "Origin: http://www.example.org\r\n" |
| 16868 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16869 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16870 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16871 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16872 | |
| 16873 | // The proxy responds to the connect with a 407, using a persistent |
| 16874 | // connection. |
| 16875 | MockRead data_reads[] = { |
| 16876 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16877 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 16878 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 16879 | "Content-Length: 0\r\n" |
| 16880 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16881 | |
| 16882 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16883 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16884 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16885 | "Upgrade: websocket\r\n" |
| 16886 | "Connection: Upgrade\r\n" |
| 16887 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16888 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16889 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16891 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16892 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16893 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16894 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 16895 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16896 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16897 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16898 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16899 | &websocket_stream_create_helper); |
| 16900 | |
| 16901 | { |
| 16902 | TestCompletionCallback callback; |
| 16903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16904 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16906 | |
| 16907 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16908 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16909 | } |
| 16910 | |
| 16911 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16912 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16913 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16914 | EXPECT_EQ(407, response->headers->response_code()); |
| 16915 | |
| 16916 | { |
| 16917 | TestCompletionCallback callback; |
| 16918 | |
| 16919 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16920 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16922 | |
| 16923 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16924 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16925 | } |
| 16926 | |
| 16927 | response = trans->GetResponseInfo(); |
| 16928 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16929 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16930 | |
| 16931 | EXPECT_EQ(101, response->headers->response_code()); |
| 16932 | |
| 16933 | trans.reset(); |
| 16934 | session->CloseAllConnections(); |
| 16935 | } |
| 16936 | |
| 16937 | // Verify that proxy headers are not sent to the destination server when |
| 16938 | // establishing a tunnel for an insecure WebSocket connection. |
| 16939 | // This requires the authentication info to be injected into the auth cache |
| 16940 | // due to crbug.com/395064 |
| 16941 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16942 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16943 | HttpRequestInfo request; |
| 16944 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16945 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 16946 | request.traffic_annotation = |
| 16947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16948 | AddWebSocketHeaders(&request.extra_headers); |
| 16949 | |
| 16950 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16951 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16952 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16953 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16954 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16956 | |
| 16957 | MockWrite data_writes[] = { |
| 16958 | // Try to establish a tunnel for the WebSocket connection, with |
| 16959 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16960 | // they cannot and will not use the same TCP/IP connection as the |
| 16961 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16962 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16963 | "Host: www.example.org:80\r\n" |
| 16964 | "Proxy-Connection: keep-alive\r\n" |
| 16965 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16966 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16967 | MockWrite("GET / HTTP/1.1\r\n" |
| 16968 | "Host: www.example.org\r\n" |
| 16969 | "Connection: Upgrade\r\n" |
| 16970 | "Upgrade: websocket\r\n" |
| 16971 | "Origin: http://www.example.org\r\n" |
| 16972 | "Sec-WebSocket-Version: 13\r\n" |
| 16973 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16974 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16975 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16976 | |
| 16977 | MockRead data_reads[] = { |
| 16978 | // HTTP CONNECT with credentials. |
| 16979 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16980 | |
| 16981 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16982 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16983 | "Upgrade: websocket\r\n" |
| 16984 | "Connection: Upgrade\r\n" |
| 16985 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16986 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16987 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16988 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16989 | |
| 16990 | session->http_auth_cache()->Add( |
| 16991 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16992 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16993 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16994 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 16995 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16996 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16997 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16998 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16999 | &websocket_stream_create_helper); |
| 17000 | |
| 17001 | TestCompletionCallback callback; |
| 17002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17003 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17005 | |
| 17006 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17007 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17008 | |
| 17009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17010 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17011 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17012 | |
| 17013 | EXPECT_EQ(101, response->headers->response_code()); |
| 17014 | |
| 17015 | trans.reset(); |
| 17016 | session->CloseAllConnections(); |
| 17017 | } |
| 17018 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17019 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17021 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17022 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17023 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17024 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17025 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17026 | |
| 17027 | HttpRequestInfo request; |
| 17028 | request.method = "POST"; |
| 17029 | request.url = GURL("http://www.foo.com/"); |
| 17030 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17031 | request.traffic_annotation = |
| 17032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17033 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17036 | MockWrite data_writes[] = { |
| 17037 | MockWrite("POST / HTTP/1.1\r\n" |
| 17038 | "Host: www.foo.com\r\n" |
| 17039 | "Connection: keep-alive\r\n" |
| 17040 | "Content-Length: 3\r\n\r\n"), |
| 17041 | MockWrite("foo"), |
| 17042 | }; |
| 17043 | |
| 17044 | MockRead data_reads[] = { |
| 17045 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17046 | MockRead(SYNCHRONOUS, OK), |
| 17047 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17048 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17049 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17050 | |
| 17051 | TestCompletionCallback callback; |
| 17052 | |
| 17053 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17054 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17055 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17056 | |
| 17057 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17058 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17059 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17060 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17061 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17062 | } |
| 17063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17064 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17065 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17066 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17067 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17068 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17069 | |
| 17070 | HttpRequestInfo request; |
| 17071 | request.method = "POST"; |
| 17072 | request.url = GURL("http://www.foo.com/"); |
| 17073 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17074 | request.traffic_annotation = |
| 17075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17079 | MockWrite data_writes[] = { |
| 17080 | MockWrite("POST / HTTP/1.1\r\n" |
| 17081 | "Host: www.foo.com\r\n" |
| 17082 | "Connection: keep-alive\r\n" |
| 17083 | "Content-Length: 3\r\n\r\n"), |
| 17084 | MockWrite("foo"), |
| 17085 | }; |
| 17086 | |
| 17087 | MockRead data_reads[] = { |
| 17088 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17089 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17090 | MockRead(SYNCHRONOUS, OK), |
| 17091 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17092 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17093 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17094 | |
| 17095 | TestCompletionCallback callback; |
| 17096 | |
| 17097 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17098 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17099 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17100 | |
| 17101 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17102 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17103 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17104 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17105 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17106 | } |
| 17107 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17108 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17109 | ChunkedUploadDataStream upload_data_stream(0); |
| 17110 | |
| 17111 | HttpRequestInfo request; |
| 17112 | request.method = "POST"; |
| 17113 | request.url = GURL("http://www.foo.com/"); |
| 17114 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17115 | request.traffic_annotation = |
| 17116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17120 | // Send headers successfully, but get an error while sending the body. |
| 17121 | MockWrite data_writes[] = { |
| 17122 | MockWrite("POST / HTTP/1.1\r\n" |
| 17123 | "Host: www.foo.com\r\n" |
| 17124 | "Connection: keep-alive\r\n" |
| 17125 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17126 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17127 | }; |
| 17128 | |
| 17129 | MockRead data_reads[] = { |
| 17130 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17131 | MockRead(SYNCHRONOUS, OK), |
| 17132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17133 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17135 | |
| 17136 | TestCompletionCallback callback; |
| 17137 | |
| 17138 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17139 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17140 | |
| 17141 | base::RunLoop().RunUntilIdle(); |
| 17142 | upload_data_stream.AppendData("f", 1, false); |
| 17143 | |
| 17144 | base::RunLoop().RunUntilIdle(); |
| 17145 | upload_data_stream.AppendData("oo", 2, true); |
| 17146 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17147 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17148 | |
| 17149 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17150 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17152 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17153 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17154 | } |
| 17155 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17156 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17157 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17158 | const std::string https_url = "https://www.example.com"; |
| 17159 | HttpRequestInfo request; |
| 17160 | request.url = GURL(https_url); |
| 17161 | request.method = "GET"; |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17162 | request.traffic_annotation = |
| 17163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17164 | |
| 17165 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17166 | ssl.ssl_info.token_binding_negotiated = true; |
| 17167 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17168 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17170 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 17171 | spdy::SpdySerializedFrame resp( |
| 17172 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 17173 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17174 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17175 | MockRead(ASYNC, ERR_IO_PENDING)}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17176 | StaticSocketDataProvider data(reads, base::span<MockWrite>()); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17178 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17179 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17181 | |
| 17182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17183 | TestCompletionCallback callback; |
| 17184 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17185 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17186 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 17187 | RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17188 | |
| 17189 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17190 | HttpRequestHeaders headers; |
| 17191 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17192 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17193 | } |
| 17194 | #endif // !defined(OS_IOS) |
| 17195 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17196 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17197 | const std::string& accept_encoding, |
| 17198 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17199 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17200 | bool should_match) { |
| 17201 | HttpRequestInfo request; |
| 17202 | request.method = "GET"; |
| 17203 | request.url = GURL("http://www.foo.com/"); |
| 17204 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17205 | accept_encoding); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17206 | request.traffic_annotation = |
| 17207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17208 | |
| 17209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17211 | // Send headers successfully, but get an error while sending the body. |
| 17212 | MockWrite data_writes[] = { |
| 17213 | MockWrite("GET / HTTP/1.1\r\n" |
| 17214 | "Host: www.foo.com\r\n" |
| 17215 | "Connection: keep-alive\r\n" |
| 17216 | "Accept-Encoding: "), |
| 17217 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17218 | }; |
| 17219 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17220 | std::string response_code = "200 OK"; |
| 17221 | std::string extra; |
| 17222 | if (!location.empty()) { |
| 17223 | response_code = "301 Redirect\r\nLocation: "; |
| 17224 | response_code.append(location); |
| 17225 | } |
| 17226 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17227 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17228 | MockRead("HTTP/1.0 "), |
| 17229 | MockRead(response_code.data()), |
| 17230 | MockRead("\r\nContent-Encoding: "), |
| 17231 | MockRead(content_encoding.data()), |
| 17232 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17233 | MockRead(SYNCHRONOUS, OK), |
| 17234 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17235 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17236 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17237 | |
| 17238 | TestCompletionCallback callback; |
| 17239 | |
| 17240 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17242 | |
| 17243 | rv = callback.WaitForResult(); |
| 17244 | if (should_match) { |
| 17245 | EXPECT_THAT(rv, IsOk()); |
| 17246 | } else { |
| 17247 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17248 | } |
| 17249 | } |
| 17250 | |
| 17251 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17252 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17253 | } |
| 17254 | |
| 17255 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17256 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17257 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17258 | } |
| 17259 | |
| 17260 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17261 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17262 | "", false); |
| 17263 | } |
| 17264 | |
| 17265 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17266 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17267 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17268 | } |
| 17269 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17270 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17271 | ProxyConfig proxy_config; |
| 17272 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17273 | proxy_config.set_pac_mandatory(true); |
| 17274 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17275 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17276 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17277 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17278 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17279 | |
| 17280 | HttpRequestInfo request; |
| 17281 | request.method = "GET"; |
| 17282 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17283 | request.traffic_annotation = |
| 17284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17285 | |
| 17286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17288 | |
| 17289 | TestCompletionCallback callback; |
| 17290 | |
| 17291 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17293 | EXPECT_THAT(callback.WaitForResult(), |
| 17294 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17295 | } |
| 17296 | |
| 17297 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17298 | ProxyConfig proxy_config; |
| 17299 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17300 | proxy_config.set_pac_mandatory(true); |
| 17301 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17302 | new MockAsyncProxyResolverFactory(false); |
| 17303 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17304 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17305 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17306 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17307 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17308 | HttpRequestInfo request; |
| 17309 | request.method = "GET"; |
| 17310 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17311 | request.traffic_annotation = |
| 17312 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17313 | |
| 17314 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17315 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17316 | |
| 17317 | TestCompletionCallback callback; |
| 17318 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17320 | |
| 17321 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17322 | ERR_FAILED, &resolver); |
| 17323 | EXPECT_THAT(callback.WaitForResult(), |
| 17324 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17325 | } |
| 17326 | |
| 17327 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17328 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17329 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17330 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17331 | session_deps_.enable_quic = false; |
| 17332 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17333 | |
| 17334 | HttpRequestInfo request; |
| 17335 | request.method = "GET"; |
| 17336 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e6 | 2018-02-07 07:41:10 | [diff] [blame] | 17337 | request.traffic_annotation = |
| 17338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17339 | |
| 17340 | TestCompletionCallback callback; |
| 17341 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17342 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17343 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17344 | |
| 17345 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17346 | } |
| 17347 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17348 | } // namespace net |