[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" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 29 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 30 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 31 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 32 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 33 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 34 | #include "net/base/completion_callback.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 35 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 36 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 37 | #include "net/base/load_timing_info.h" |
| 38 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 39 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 40 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 41 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 42 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 43 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 44 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 45 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 46 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 47 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 48 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 49 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 50 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 51 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 55 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 56 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 57 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 58 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 59 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 60 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 61 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 62 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 63 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 64 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 65 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 66 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 67 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 68 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 69 | #include "net/log/test_net_log_entry.h" |
| 70 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 71 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 72 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 73 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 74 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 75 | #include "net/proxy_resolution/proxy_resolver.h" |
| 76 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 77 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 80 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 81 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 82 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 83 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/socket_test_util.h" |
| 85 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 86 | #include "net/spdy/chromium/spdy_session.h" |
| 87 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 88 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 89 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 94 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 95 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 96 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 97 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 98 | #include "net/test/test_data_directory.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 99 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 100 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 101 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 102 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 103 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 104 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 105 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 106 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 107 | #if defined(NTLM_PORTABLE) |
| 108 | #include "base/base64.h" |
| 109 | #include "net/ntlm/ntlm_test_data.h" |
| 110 | #endif |
| 111 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 112 | using net::test::IsError; |
| 113 | using net::test::IsOk; |
| 114 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 115 | using base::ASCIIToUTF16; |
| 116 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 117 | //----------------------------------------------------------------------------- |
| 118 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 119 | namespace net { |
| 120 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 121 | namespace { |
| 122 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 123 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 124 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 125 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 126 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 127 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 128 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 129 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 130 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 131 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 132 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 133 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 134 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 135 | const char kAlternativeServiceHttpHeader[] = |
| 136 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 137 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 138 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 139 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 140 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 141 | } |
| 142 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 143 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 144 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 145 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 146 | } |
| 147 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 148 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 149 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 150 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 151 | } |
| 152 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 153 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 154 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 155 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 156 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 157 | if (!params) |
| 158 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 159 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 160 | if (!params->GetList("headers", &header_list)) |
| 161 | return false; |
| 162 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 163 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 164 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 165 | return true; |
| 166 | } |
| 167 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 168 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 169 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 170 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 171 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 172 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 173 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 174 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 175 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 176 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 177 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 178 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 179 | |
| 180 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 181 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 182 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 183 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 184 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 185 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 189 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 190 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 191 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 192 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 193 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 194 | |
| 195 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 196 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 197 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 198 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 199 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 201 | load_timing_info.send_start); |
| 202 | |
| 203 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 204 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 205 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 207 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 208 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 212 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 213 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 214 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 215 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 217 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | |
| 219 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 220 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 221 | load_timing_info.proxy_resolve_end); |
| 222 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 223 | load_timing_info.send_start); |
| 224 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 226 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 228 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 229 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 233 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 234 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | int connect_timing_flags) { |
| 236 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 237 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | |
| 239 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 240 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 241 | load_timing_info.proxy_resolve_end); |
| 242 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 243 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 244 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 245 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 247 | load_timing_info.send_start); |
| 248 | |
| 249 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 250 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 251 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 252 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 253 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 254 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 255 | } |
| 256 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 257 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 258 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 259 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 260 | } |
| 261 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 262 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 263 | public: |
| 264 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 265 | |
| 266 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 267 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 268 | std::unique_ptr<ProxyResolver>* result, |
| 269 | const CompletionCallback& callback, |
| 270 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 271 | return ERR_PAC_SCRIPT_FAILED; |
| 272 | } |
| 273 | }; |
| 274 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame^] | 275 | class TestSSLConfigService : public SSLConfigService { |
| 276 | public: |
| 277 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
| 278 | |
| 279 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 280 | |
| 281 | private: |
| 282 | ~TestSSLConfigService() override = default; |
| 283 | |
| 284 | SSLConfig config_; |
| 285 | }; |
| 286 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 287 | } // namespace |
| 288 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 289 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 290 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 291 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 292 | // Important to restore the per-pool limit first, since the pool limit must |
| 293 | // always be greater than group limit, and the tests reduce both limits. |
| 294 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 295 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 296 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 297 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 298 | } |
| 299 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 300 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 301 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 302 | : ssl_(ASYNC, OK), |
| 303 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 304 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 305 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 306 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 307 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 308 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 309 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 310 | struct SimpleGetHelperResult { |
| 311 | int rv; |
| 312 | std::string status_line; |
| 313 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 314 | int64_t total_received_bytes; |
| 315 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 316 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 317 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 318 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 319 | }; |
| 320 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 321 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 322 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 323 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 324 | } |
| 325 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 326 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 327 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 328 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 329 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 330 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 331 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 332 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 333 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 336 | // Either |write_failure| specifies a write failure or |read_failure| |
| 337 | // specifies a read failure when using a reused socket. In either case, the |
| 338 | // failure should cause the network transaction to resend the request, and the |
| 339 | // other argument should be NULL. |
| 340 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 341 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 342 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 343 | // Either |write_failure| specifies a write failure or |read_failure| |
| 344 | // specifies a read failure when using a reused socket. In either case, the |
| 345 | // failure should cause the network transaction to resend the request, and the |
| 346 | // other argument should be NULL. |
| 347 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 348 | const MockRead* read_failure, |
| 349 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 350 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 351 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 352 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 353 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 354 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 355 | HttpRequestInfo request; |
| 356 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 357 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 358 | request.traffic_annotation = |
| 359 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 360 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 361 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 362 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 363 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 365 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 366 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 367 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 368 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 370 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 371 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 372 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 373 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 375 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 376 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 377 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 378 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 379 | |
| 380 | // Even in the failure cases that use this function, connections are always |
| 381 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 382 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 383 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 384 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 385 | if (out.rv != OK) |
| 386 | return out; |
| 387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 388 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 389 | // Can't use ASSERT_* inside helper functions like this, so |
| 390 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 391 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 392 | out.rv = ERR_UNEXPECTED; |
| 393 | return out; |
| 394 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 395 | out.status_line = response->headers->GetStatusLine(); |
| 396 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 397 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 398 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 399 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 400 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 401 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 402 | EXPECT_EQ(got_endpoint, |
| 403 | out.remote_endpoint_after_start.address().size() > 0); |
| 404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 405 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 407 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 408 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 409 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 410 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 411 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 412 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 413 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 414 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 415 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 416 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 417 | std::string line; |
| 418 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 419 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 420 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 421 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 422 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 423 | std::string value; |
| 424 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 425 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 426 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 427 | EXPECT_EQ("keep-alive", value); |
| 428 | |
| 429 | std::string response_headers; |
| 430 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 431 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 432 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 434 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 435 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 436 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 438 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 439 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 440 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 441 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 442 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 443 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 444 | MockWrite data_writes[] = { |
| 445 | MockWrite("GET / HTTP/1.1\r\n" |
| 446 | "Host: www.example.org\r\n" |
| 447 | "Connection: keep-alive\r\n\r\n"), |
| 448 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 449 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 450 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 451 | arraysize(data_writes)); |
| 452 | StaticSocketDataProvider* data[] = {&reads}; |
| 453 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 454 | |
| 455 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 456 | out.total_sent_bytes); |
| 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, |
| 576 | const CompletionCallback& 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 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 726 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 727 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 728 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 729 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 730 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 731 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 732 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 733 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 734 | |
| 735 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 739 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 741 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 743 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 744 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 745 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 746 | EXPECT_THAT(out.rv, IsOk()); |
| 747 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 748 | EXPECT_EQ("hello world", out.response_data); |
| 749 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 750 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 751 | } |
| 752 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 753 | // Response with no status line, and a weird port. Should fail by default. |
| 754 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 755 | MockRead data_reads[] = { |
| 756 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 757 | }; |
| 758 | |
| 759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 760 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 761 | |
| 762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 763 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 764 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 765 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 766 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 767 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 768 | request.method = "GET"; |
| 769 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 770 | request.traffic_annotation = |
| 771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 772 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 773 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 774 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 775 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 776 | } |
| 777 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 778 | // Tests that request info can be destroyed after the headers phase is complete. |
| 779 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 781 | auto trans = |
| 782 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 783 | |
| 784 | MockRead data_reads[] = { |
| 785 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 786 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 787 | }; |
| 788 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 790 | |
| 791 | TestCompletionCallback callback; |
| 792 | |
| 793 | { |
| 794 | auto request = std::make_unique<HttpRequestInfo>(); |
| 795 | request->method = "GET"; |
| 796 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 797 | request->traffic_annotation = |
| 798 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 799 | |
| 800 | int rv = |
| 801 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 802 | |
| 803 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 804 | } // Let request info be destroyed. |
| 805 | |
| 806 | trans.reset(); |
| 807 | } |
| 808 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 809 | // Response with no status line, and a weird port. Option to allow weird ports |
| 810 | // enabled. |
| 811 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 812 | MockRead data_reads[] = { |
| 813 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 814 | }; |
| 815 | |
| 816 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 817 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 818 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 819 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 820 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 821 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 822 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 823 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 824 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 825 | request.method = "GET"; |
| 826 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 827 | request.traffic_annotation = |
| 828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 829 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 830 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 831 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 832 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 833 | |
| 834 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 835 | ASSERT_TRUE(info->headers); |
| 836 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 837 | |
| 838 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 839 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 840 | } |
| 841 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 843 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 844 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 845 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 847 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 848 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 849 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 850 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 851 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 852 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 853 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 854 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 858 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 859 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 860 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 861 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 862 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 863 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 864 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 865 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 866 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 867 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 868 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 869 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 873 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 874 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 875 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 876 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 877 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 878 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 879 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 880 | EXPECT_THAT(out.rv, IsOk()); |
| 881 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 882 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 883 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 884 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 888 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 889 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 890 | MockRead("\n"), |
| 891 | MockRead("\n"), |
| 892 | MockRead("Q"), |
| 893 | MockRead("J"), |
| 894 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 895 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 896 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 897 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 898 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 899 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 900 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 901 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 902 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 903 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 907 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 908 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 909 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 914 | EXPECT_THAT(out.rv, IsOk()); |
| 915 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 916 | EXPECT_EQ("HTT", out.response_data); |
| 917 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 918 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 919 | } |
| 920 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 921 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 922 | // persistent connection. The response should still terminate since a 204 |
| 923 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 924 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 925 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 926 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 927 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 928 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 930 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 931 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 932 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 933 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 934 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 935 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 936 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 937 | int64_t response_size = reads_size - strlen(junk); |
| 938 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 939 | } |
| 940 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 941 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 942 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 943 | std::string final_chunk = "0\r\n\r\n"; |
| 944 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 945 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 946 | MockRead data_reads[] = { |
| 947 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 948 | MockRead("5\r\nHello\r\n"), |
| 949 | MockRead("1\r\n"), |
| 950 | MockRead(" \r\n"), |
| 951 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 952 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 953 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 954 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 955 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 956 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 957 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 958 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 959 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 960 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 961 | int64_t response_size = reads_size - extra_data.size(); |
| 962 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 963 | } |
| 964 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 965 | // Next tests deal with http://crbug.com/56344. |
| 966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 967 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 968 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 969 | MockRead data_reads[] = { |
| 970 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 971 | MockRead("Content-Length: 10\r\n"), |
| 972 | MockRead("Content-Length: 5\r\n\r\n"), |
| 973 | }; |
| 974 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 975 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 976 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 977 | } |
| 978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 979 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 980 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 981 | MockRead data_reads[] = { |
| 982 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 983 | MockRead("Content-Length: 5\r\n"), |
| 984 | MockRead("Content-Length: 5\r\n\r\n"), |
| 985 | MockRead("Hello"), |
| 986 | }; |
| 987 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 988 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 989 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 990 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 991 | EXPECT_EQ("Hello", out.response_data); |
| 992 | } |
| 993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 995 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 996 | // More than 2 dupes. |
| 997 | { |
| 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1000 | MockRead("Content-Length: 5\r\n"), |
| 1001 | MockRead("Content-Length: 5\r\n"), |
| 1002 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1003 | MockRead("Hello"), |
| 1004 | }; |
| 1005 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1006 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1007 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1008 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1009 | EXPECT_EQ("Hello", out.response_data); |
| 1010 | } |
| 1011 | // HTTP/1.0 |
| 1012 | { |
| 1013 | MockRead data_reads[] = { |
| 1014 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1015 | MockRead("Content-Length: 5\r\n"), |
| 1016 | MockRead("Content-Length: 5\r\n"), |
| 1017 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1018 | MockRead("Hello"), |
| 1019 | }; |
| 1020 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1021 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1022 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1023 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1024 | EXPECT_EQ("Hello", out.response_data); |
| 1025 | } |
| 1026 | // 2 dupes and one mismatched. |
| 1027 | { |
| 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1030 | MockRead("Content-Length: 10\r\n"), |
| 1031 | MockRead("Content-Length: 10\r\n"), |
| 1032 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1033 | }; |
| 1034 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1035 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1036 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1040 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1041 | MultipleContentLengthHeadersTransferEncoding) { |
| 1042 | MockRead data_reads[] = { |
| 1043 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1044 | MockRead("Content-Length: 666\r\n"), |
| 1045 | MockRead("Content-Length: 1337\r\n"), |
| 1046 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1047 | MockRead("5\r\nHello\r\n"), |
| 1048 | MockRead("1\r\n"), |
| 1049 | MockRead(" \r\n"), |
| 1050 | MockRead("5\r\nworld\r\n"), |
| 1051 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1052 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1053 | }; |
| 1054 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1055 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1056 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1057 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1058 | EXPECT_EQ("Hello world", out.response_data); |
| 1059 | } |
| 1060 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1061 | // Next tests deal with http://crbug.com/98895. |
| 1062 | |
| 1063 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1064 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1065 | MockRead data_reads[] = { |
| 1066 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1067 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
| 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1072 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1073 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1074 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1075 | EXPECT_EQ("Hello", out.response_data); |
| 1076 | } |
| 1077 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1078 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1079 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1080 | MockRead data_reads[] = { |
| 1081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1082 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1083 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1084 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1085 | MockRead("Hello"), |
| 1086 | }; |
| 1087 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1088 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1089 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1090 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1091 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1095 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1096 | MockRead data_reads[] = { |
| 1097 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1098 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1099 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1100 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1101 | MockRead("Hello"), |
| 1102 | }; |
| 1103 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1104 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1105 | EXPECT_THAT(out.rv, |
| 1106 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1107 | } |
| 1108 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1109 | // Checks that two identical Location headers result in no error. |
| 1110 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1111 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1112 | MockRead data_reads[] = { |
| 1113 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1114 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1115 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1116 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1117 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1118 | }; |
| 1119 | |
| 1120 | HttpRequestInfo request; |
| 1121 | request.method = "GET"; |
| 1122 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1123 | request.traffic_annotation = |
| 1124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1125 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1127 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1128 | |
| 1129 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1130 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1131 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1132 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1133 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1134 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1135 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1136 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1137 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1140 | ASSERT_TRUE(response); |
| 1141 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1142 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1143 | std::string url; |
| 1144 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1145 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1146 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1147 | } |
| 1148 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1149 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1150 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | MockRead data_reads[] = { |
| 1152 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1153 | MockRead("Location: http://good.com/\r\n"), |
| 1154 | MockRead("Location: http://evil.com/\r\n"), |
| 1155 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1156 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | }; |
| 1158 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1159 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1160 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | } |
| 1162 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1163 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1164 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1165 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1167 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1168 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1169 | request.traffic_annotation = |
| 1170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1174 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1175 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1176 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1177 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1178 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1179 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1180 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1181 | "Host: www.example.org\r\n" |
| 1182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1183 | }; |
| 1184 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1185 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1186 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1187 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1188 | // No response body because the test stops reading here. |
| 1189 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1190 | }; |
| 1191 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1192 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1193 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1194 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1196 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1197 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1198 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1199 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1200 | |
| 1201 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1202 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1203 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1204 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1205 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1206 | |
| 1207 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1208 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1209 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1210 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1211 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1212 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1213 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1214 | |
| 1215 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1216 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | bool has_server_header = response->headers->EnumerateHeader( |
| 1218 | &iter, "Server", &server_header); |
| 1219 | EXPECT_TRUE(has_server_header); |
| 1220 | EXPECT_EQ("Blah", server_header); |
| 1221 | |
| 1222 | // Reading should give EOF right away, since there is no message body |
| 1223 | // (despite non-zero content-length). |
| 1224 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1225 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1226 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1227 | EXPECT_EQ("", response_data); |
| 1228 | } |
| 1229 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1230 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1232 | |
| 1233 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1234 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1235 | MockRead("hello"), |
| 1236 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1237 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1238 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1239 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1240 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1241 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1242 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1243 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1244 | "hello", "world" |
| 1245 | }; |
| 1246 | |
| 1247 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1248 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1249 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1250 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1251 | request.traffic_annotation = |
| 1252 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1256 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1257 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1258 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1260 | |
| 1261 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1262 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1264 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1265 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1266 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1267 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1268 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1269 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1270 | |
| 1271 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1272 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1274 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1278 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1279 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1280 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1281 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1282 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1283 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1284 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1285 | request.method = "POST"; |
| 1286 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1287 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1288 | request.traffic_annotation = |
| 1289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1290 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1291 | // Check the upload progress returned before initialization is correct. |
| 1292 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1293 | EXPECT_EQ(0u, progress.size()); |
| 1294 | EXPECT_EQ(0u, progress.position()); |
| 1295 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1297 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1298 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1300 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1301 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1302 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1303 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1305 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1306 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1308 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1310 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | |
| 1313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1314 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1316 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1317 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1319 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1320 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | |
| 1322 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1323 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1325 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1326 | } |
| 1327 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1328 | // This test is almost the same as Ignores100 above, but the response contains |
| 1329 | // 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] | 1330 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1331 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1332 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1333 | request.method = "GET"; |
| 1334 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1335 | request.traffic_annotation = |
| 1336 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1340 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1341 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1342 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1343 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1344 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1345 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1346 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1348 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1349 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1350 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1351 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1352 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1353 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1354 | |
| 1355 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1356 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1359 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1360 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1361 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1362 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1363 | |
| 1364 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1365 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1366 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1367 | EXPECT_EQ("hello world", response_data); |
| 1368 | } |
| 1369 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1370 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1371 | HttpRequestInfo request; |
| 1372 | request.method = "POST"; |
| 1373 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1374 | request.traffic_annotation = |
| 1375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1376 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1379 | |
| 1380 | MockRead data_reads[] = { |
| 1381 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1382 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1383 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1384 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1385 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1386 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1387 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1388 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1391 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1392 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1394 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1395 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1396 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1397 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1398 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1399 | } |
| 1400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1401 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1402 | HttpRequestInfo request; |
| 1403 | request.method = "POST"; |
| 1404 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1405 | request.traffic_annotation = |
| 1406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1409 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1410 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1411 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1412 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1413 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1414 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1416 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1417 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1419 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1421 | |
| 1422 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1424 | } |
| 1425 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1426 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1427 | const MockWrite* write_failure, |
| 1428 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1429 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1430 | request.method = "GET"; |
| 1431 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1432 | request.traffic_annotation = |
| 1433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1434 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1435 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1436 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1438 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1439 | // Written data for successfully sending both requests. |
| 1440 | MockWrite data1_writes[] = { |
| 1441 | MockWrite("GET / HTTP/1.1\r\n" |
| 1442 | "Host: www.foo.com\r\n" |
| 1443 | "Connection: keep-alive\r\n\r\n"), |
| 1444 | MockWrite("GET / HTTP/1.1\r\n" |
| 1445 | "Host: www.foo.com\r\n" |
| 1446 | "Connection: keep-alive\r\n\r\n") |
| 1447 | }; |
| 1448 | |
| 1449 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1450 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1451 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1452 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1453 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1454 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1455 | |
| 1456 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1457 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1458 | data1_writes[1] = *write_failure; |
| 1459 | } else { |
| 1460 | ASSERT_TRUE(read_failure); |
| 1461 | data1_reads[2] = *read_failure; |
| 1462 | } |
| 1463 | |
| 1464 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1465 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1466 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1467 | |
| 1468 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1469 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1470 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1471 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1472 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1473 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1474 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1475 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1476 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1477 | "hello", "world" |
| 1478 | }; |
| 1479 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1480 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1481 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1482 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1484 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1485 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1486 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1488 | |
| 1489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1490 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1491 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1492 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1493 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1494 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1495 | if (i == 0) { |
| 1496 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1497 | } else { |
| 1498 | // The second request should be using a new socket. |
| 1499 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1500 | } |
| 1501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1503 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1504 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1505 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1506 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1507 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1508 | |
| 1509 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1510 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1511 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1512 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1513 | } |
| 1514 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1515 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1516 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1517 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1518 | const MockRead* read_failure, |
| 1519 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1520 | HttpRequestInfo request; |
| 1521 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1522 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1523 | request.traffic_annotation = |
| 1524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1525 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1526 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1527 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1529 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1530 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1531 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1532 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1533 | ssl1.next_proto = kProtoHTTP2; |
| 1534 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1535 | } |
| 1536 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1537 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1538 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1539 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1540 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1541 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1542 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1543 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1544 | SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1545 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1546 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1547 | // HTTP/1.1 versions of the request and response. |
| 1548 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1549 | "Host: www.foo.com\r\n" |
| 1550 | "Connection: keep-alive\r\n\r\n"; |
| 1551 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1552 | const char kHttpData[] = "hello"; |
| 1553 | |
| 1554 | std::vector<MockRead> data1_reads; |
| 1555 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | if (write_failure) { |
| 1557 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1558 | data1_writes.push_back(*write_failure); |
| 1559 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1560 | } else { |
| 1561 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1562 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1563 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1564 | } else { |
| 1565 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1566 | } |
| 1567 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1568 | } |
| 1569 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1570 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1571 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1572 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1573 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1574 | std::vector<MockRead> data2_reads; |
| 1575 | std::vector<MockWrite> data2_writes; |
| 1576 | |
| 1577 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1578 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1579 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1580 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1581 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1582 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1583 | } else { |
| 1584 | data2_writes.push_back( |
| 1585 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1586 | |
| 1587 | data2_reads.push_back( |
| 1588 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1589 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1590 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1591 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1592 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1593 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1594 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1595 | |
| 1596 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1597 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1598 | // Wait for the preconnect to complete. |
| 1599 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1600 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1601 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1602 | |
| 1603 | // Make the request. |
| 1604 | TestCompletionCallback callback; |
| 1605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1607 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1608 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1610 | |
| 1611 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1612 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1613 | |
| 1614 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1615 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1616 | TestLoadTimingNotReused( |
| 1617 | load_timing_info, |
| 1618 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1620 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1621 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1622 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1623 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1624 | if (response->was_fetched_via_spdy) { |
| 1625 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1626 | } else { |
| 1627 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1628 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1629 | |
| 1630 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1631 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1633 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1634 | } |
| 1635 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1636 | // Test that we do not retry indefinitely when a server sends an error like |
| 1637 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1638 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1639 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1640 | HttpRequestInfo request; |
| 1641 | request.method = "GET"; |
| 1642 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1643 | request.traffic_annotation = |
| 1644 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1645 | |
| 1646 | // Check whether we give up after the third try. |
| 1647 | |
| 1648 | // Construct an HTTP2 request and a "Go away" response. |
| 1649 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1650 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1651 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1652 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1653 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1654 | |
| 1655 | // Three go away responses. |
| 1656 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1657 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1658 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1659 | |
| 1660 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1661 | AddSSLSocketData(); |
| 1662 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1663 | AddSSLSocketData(); |
| 1664 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1665 | AddSSLSocketData(); |
| 1666 | |
| 1667 | TestCompletionCallback callback; |
| 1668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1670 | |
| 1671 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1673 | |
| 1674 | rv = callback.WaitForResult(); |
| 1675 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1676 | } |
| 1677 | |
| 1678 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1679 | HttpRequestInfo request; |
| 1680 | request.method = "GET"; |
| 1681 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1682 | request.traffic_annotation = |
| 1683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1684 | |
| 1685 | // Check whether we try atleast thrice before giving up. |
| 1686 | |
| 1687 | // Construct an HTTP2 request and a "Go away" response. |
| 1688 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1689 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1690 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1691 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1692 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1693 | |
| 1694 | // Construct a non error HTTP2 response. |
| 1695 | SpdySerializedFrame spdy_response_no_error( |
| 1696 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1697 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1698 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1699 | CreateMockRead(spdy_data, 2)}; |
| 1700 | |
| 1701 | // Two error responses. |
| 1702 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1703 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1704 | // Followed by a success response. |
| 1705 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1706 | |
| 1707 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1708 | AddSSLSocketData(); |
| 1709 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1710 | AddSSLSocketData(); |
| 1711 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1712 | AddSSLSocketData(); |
| 1713 | |
| 1714 | TestCompletionCallback callback; |
| 1715 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1717 | |
| 1718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1720 | |
| 1721 | rv = callback.WaitForResult(); |
| 1722 | EXPECT_THAT(rv, IsOk()); |
| 1723 | } |
| 1724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1725 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1726 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1727 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1728 | } |
| 1729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1730 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1731 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1732 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1733 | } |
| 1734 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1735 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1736 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1737 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1738 | } |
| 1739 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1740 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1741 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1742 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1743 | MockRead read_failure(SYNCHRONOUS, |
| 1744 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1745 | "Connection: Keep-Alive\r\n" |
| 1746 | "Content-Length: 6\r\n\r\n" |
| 1747 | "Pickle"); |
| 1748 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1749 | } |
| 1750 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1751 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1752 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1753 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1754 | } |
| 1755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1756 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1757 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1758 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1759 | } |
| 1760 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1761 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1762 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1764 | } |
| 1765 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1766 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1767 | MockRead read_failure(ASYNC, OK); // EOF |
| 1768 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1769 | } |
| 1770 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1771 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1772 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1773 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1774 | MockRead read_failure(SYNCHRONOUS, |
| 1775 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1776 | "Connection: Keep-Alive\r\n" |
| 1777 | "Content-Length: 6\r\n\r\n" |
| 1778 | "Pickle"); |
| 1779 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1780 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1781 | } |
| 1782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1783 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1784 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1785 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1786 | } |
| 1787 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1788 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1789 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1790 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1791 | } |
| 1792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1793 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1794 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1795 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1796 | } |
| 1797 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1798 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1799 | MockRead read_failure(ASYNC, OK); // EOF |
| 1800 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | } |
| 1802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1803 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1804 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1806 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1807 | request.traffic_annotation = |
| 1808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1812 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1813 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1814 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1815 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1816 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1817 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1818 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1822 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1823 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1824 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1826 | |
| 1827 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1828 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1829 | |
| 1830 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1831 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1832 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | // What do various browsers do when the server closes a non-keepalive |
| 1836 | // connection without sending any response header or body? |
| 1837 | // |
| 1838 | // IE7: error page |
| 1839 | // Safari 3.1.2 (Windows): error page |
| 1840 | // Firefox 3.0.1: blank page |
| 1841 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1842 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1843 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1844 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1845 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1846 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1847 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1848 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1849 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1850 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1851 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1852 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1853 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1854 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1855 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1856 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1857 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1858 | // destructor in such situations. |
| 1859 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1860 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1861 | HttpRequestInfo request; |
| 1862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1863 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1864 | request.traffic_annotation = |
| 1865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1866 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1868 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1869 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1870 | |
| 1871 | MockRead data_reads[] = { |
| 1872 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1873 | MockRead("Connection: keep-alive\r\n"), |
| 1874 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1875 | MockRead("hello"), |
| 1876 | MockRead(SYNCHRONOUS, 0), |
| 1877 | }; |
| 1878 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1880 | |
| 1881 | TestCompletionCallback callback; |
| 1882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1883 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1885 | |
| 1886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1888 | |
| 1889 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1890 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1891 | if (rv == ERR_IO_PENDING) |
| 1892 | rv = callback.WaitForResult(); |
| 1893 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1894 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1895 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1896 | |
| 1897 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1898 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1899 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1900 | } |
| 1901 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1902 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1903 | HttpRequestInfo request; |
| 1904 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1905 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1906 | request.traffic_annotation = |
| 1907 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1910 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1911 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1912 | |
| 1913 | MockRead data_reads[] = { |
| 1914 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1915 | MockRead("Connection: keep-alive\r\n"), |
| 1916 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1917 | MockRead(SYNCHRONOUS, 0), |
| 1918 | }; |
| 1919 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1921 | |
| 1922 | TestCompletionCallback callback; |
| 1923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1924 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1926 | |
| 1927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1929 | |
| 1930 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1931 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1932 | if (rv == ERR_IO_PENDING) |
| 1933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1934 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1935 | |
| 1936 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1937 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1938 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1939 | } |
| 1940 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1941 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1942 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1943 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1944 | HttpRequestInfo request; |
| 1945 | request.method = "GET"; |
| 1946 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1947 | request.traffic_annotation = |
| 1948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1949 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1950 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1951 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1953 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1954 | const char* request_data = |
| 1955 | "GET / HTTP/1.1\r\n" |
| 1956 | "Host: www.foo.com\r\n" |
| 1957 | "Connection: keep-alive\r\n\r\n"; |
| 1958 | MockWrite data_writes[] = { |
| 1959 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1960 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1961 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1962 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1963 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1964 | }; |
| 1965 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1966 | // Note that because all these reads happen in the same |
| 1967 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1968 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1969 | MockRead data_reads[] = { |
| 1970 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1971 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1972 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1973 | MockRead(ASYNC, 7, |
| 1974 | "HTTP/1.1 302 Found\r\n" |
| 1975 | "Content-Length: 0\r\n\r\n"), |
| 1976 | MockRead(ASYNC, 9, |
| 1977 | "HTTP/1.1 302 Found\r\n" |
| 1978 | "Content-Length: 5\r\n\r\n" |
| 1979 | "hello"), |
| 1980 | MockRead(ASYNC, 11, |
| 1981 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1982 | "Content-Length: 0\r\n\r\n"), |
| 1983 | MockRead(ASYNC, 13, |
| 1984 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1985 | "Content-Length: 5\r\n\r\n" |
| 1986 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1987 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1988 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1989 | // the set_busy_before_sync_reads(true) call, while the |
| 1990 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1991 | // reuseable. See http://crbug.com/544255. |
| 1992 | MockRead(ASYNC, 15, |
| 1993 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1994 | "Content-Length: 5\r\n\r\n"), |
| 1995 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1996 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1997 | MockRead(ASYNC, 18, |
| 1998 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1999 | "Content-Length: 5\r\n\r\n" |
| 2000 | "he"), |
| 2001 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2002 | |
| 2003 | // The body of the final request is actually read. |
| 2004 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2005 | MockRead(ASYNC, 22, "hello"), |
| 2006 | }; |
| 2007 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2008 | arraysize(data_writes)); |
| 2009 | data.set_busy_before_sync_reads(true); |
| 2010 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2011 | |
| 2012 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2013 | std::string response_lines[kNumUnreadBodies]; |
| 2014 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2015 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2016 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2017 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2018 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2019 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2020 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2022 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2023 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2024 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2025 | LoadTimingInfo load_timing_info; |
| 2026 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2027 | if (i == 0) { |
| 2028 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2029 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2030 | } else { |
| 2031 | TestLoadTimingReused(load_timing_info); |
| 2032 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2033 | } |
| 2034 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2035 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2036 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2037 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2038 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2039 | response_lines[i] = response->headers->GetStatusLine(); |
| 2040 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2041 | // Delete the transaction without reading the response bodies. Then spin |
| 2042 | // the message loop, so the response bodies are drained. |
| 2043 | trans.reset(); |
| 2044 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2045 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2046 | |
| 2047 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2048 | "HTTP/1.1 204 No Content", |
| 2049 | "HTTP/1.1 205 Reset Content", |
| 2050 | "HTTP/1.1 304 Not Modified", |
| 2051 | "HTTP/1.1 302 Found", |
| 2052 | "HTTP/1.1 302 Found", |
| 2053 | "HTTP/1.1 301 Moved Permanently", |
| 2054 | "HTTP/1.1 301 Moved Permanently", |
| 2055 | "HTTP/1.1 200 Hunky-Dory", |
| 2056 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2057 | }; |
| 2058 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2059 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2060 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2061 | |
| 2062 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2063 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2065 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2066 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2067 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2068 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2069 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2070 | ASSERT_TRUE(response); |
| 2071 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2072 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2073 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2074 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2076 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2077 | } |
| 2078 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2079 | // Sockets that receive extra data after a response is complete should not be |
| 2080 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2081 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2083 | MockWrite data_writes1[] = { |
| 2084 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2085 | "Host: www.borked.com\r\n" |
| 2086 | "Connection: keep-alive\r\n\r\n"), |
| 2087 | }; |
| 2088 | |
| 2089 | MockRead data_reads1[] = { |
| 2090 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2091 | "Connection: keep-alive\r\n" |
| 2092 | "Content-Length: 22\r\n\r\n" |
| 2093 | "This server is borked."), |
| 2094 | }; |
| 2095 | |
| 2096 | MockWrite data_writes2[] = { |
| 2097 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2098 | "Host: www.borked.com\r\n" |
| 2099 | "Connection: keep-alive\r\n\r\n"), |
| 2100 | }; |
| 2101 | |
| 2102 | MockRead data_reads2[] = { |
| 2103 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2104 | "Content-Length: 3\r\n\r\n" |
| 2105 | "foo"), |
| 2106 | }; |
| 2107 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2108 | data_writes1, arraysize(data_writes1)); |
| 2109 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2110 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2111 | data_writes2, arraysize(data_writes2)); |
| 2112 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2113 | |
| 2114 | TestCompletionCallback callback; |
| 2115 | HttpRequestInfo request1; |
| 2116 | request1.method = "HEAD"; |
| 2117 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2118 | request1.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 trans1 = |
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 | int rv = trans1->Start(&request1, 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* response1 = trans1->GetResponseInfo(); |
| 2127 | ASSERT_TRUE(response1); |
| 2128 | ASSERT_TRUE(response1->headers); |
| 2129 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2130 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2131 | |
| 2132 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2133 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2134 | EXPECT_EQ("", response_data1); |
| 2135 | // Deleting the transaction attempts to release the socket back into the |
| 2136 | // socket pool. |
| 2137 | trans1.reset(); |
| 2138 | |
| 2139 | HttpRequestInfo request2; |
| 2140 | request2.method = "GET"; |
| 2141 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2142 | request2.traffic_annotation = |
| 2143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2144 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2145 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2146 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2147 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2148 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2149 | |
| 2150 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2151 | ASSERT_TRUE(response2); |
| 2152 | ASSERT_TRUE(response2->headers); |
| 2153 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2154 | |
| 2155 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2157 | EXPECT_EQ("foo", response_data2); |
| 2158 | } |
| 2159 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2160 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2162 | MockWrite data_writes1[] = { |
| 2163 | MockWrite("GET / HTTP/1.1\r\n" |
| 2164 | "Host: www.borked.com\r\n" |
| 2165 | "Connection: keep-alive\r\n\r\n"), |
| 2166 | }; |
| 2167 | |
| 2168 | MockRead data_reads1[] = { |
| 2169 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2170 | "Connection: keep-alive\r\n" |
| 2171 | "Content-Length: 22\r\n\r\n" |
| 2172 | "This server is borked." |
| 2173 | "Bonus data!"), |
| 2174 | }; |
| 2175 | |
| 2176 | MockWrite data_writes2[] = { |
| 2177 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2178 | "Host: www.borked.com\r\n" |
| 2179 | "Connection: keep-alive\r\n\r\n"), |
| 2180 | }; |
| 2181 | |
| 2182 | MockRead data_reads2[] = { |
| 2183 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2184 | "Content-Length: 3\r\n\r\n" |
| 2185 | "foo"), |
| 2186 | }; |
| 2187 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2188 | data_writes1, arraysize(data_writes1)); |
| 2189 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2190 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2191 | data_writes2, arraysize(data_writes2)); |
| 2192 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2193 | |
| 2194 | TestCompletionCallback callback; |
| 2195 | HttpRequestInfo request1; |
| 2196 | request1.method = "GET"; |
| 2197 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2198 | request1.traffic_annotation = |
| 2199 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2200 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2201 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2202 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2203 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2204 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2205 | |
| 2206 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2207 | ASSERT_TRUE(response1); |
| 2208 | ASSERT_TRUE(response1->headers); |
| 2209 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2210 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2211 | |
| 2212 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2213 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2214 | EXPECT_EQ("This server is borked.", response_data1); |
| 2215 | // Deleting the transaction attempts to release the socket back into the |
| 2216 | // socket pool. |
| 2217 | trans1.reset(); |
| 2218 | |
| 2219 | HttpRequestInfo request2; |
| 2220 | request2.method = "GET"; |
| 2221 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2222 | request2.traffic_annotation = |
| 2223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2224 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2225 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2226 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2227 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2228 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2229 | |
| 2230 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2231 | ASSERT_TRUE(response2); |
| 2232 | ASSERT_TRUE(response2->headers); |
| 2233 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2234 | |
| 2235 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2236 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2237 | EXPECT_EQ("foo", response_data2); |
| 2238 | } |
| 2239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2240 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2242 | MockWrite data_writes1[] = { |
| 2243 | MockWrite("GET / HTTP/1.1\r\n" |
| 2244 | "Host: www.borked.com\r\n" |
| 2245 | "Connection: keep-alive\r\n\r\n"), |
| 2246 | }; |
| 2247 | |
| 2248 | MockRead data_reads1[] = { |
| 2249 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2250 | "Connection: keep-alive\r\n" |
| 2251 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2252 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2253 | MockRead("0\r\n\r\nBonus data!"), |
| 2254 | }; |
| 2255 | |
| 2256 | MockWrite data_writes2[] = { |
| 2257 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2258 | "Host: www.borked.com\r\n" |
| 2259 | "Connection: keep-alive\r\n\r\n"), |
| 2260 | }; |
| 2261 | |
| 2262 | MockRead data_reads2[] = { |
| 2263 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2264 | "Content-Length: 3\r\n\r\n" |
| 2265 | "foo"), |
| 2266 | }; |
| 2267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2268 | data_writes1, arraysize(data_writes1)); |
| 2269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2270 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2271 | data_writes2, arraysize(data_writes2)); |
| 2272 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2273 | |
| 2274 | TestCompletionCallback callback; |
| 2275 | HttpRequestInfo request1; |
| 2276 | request1.method = "GET"; |
| 2277 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2278 | request1.traffic_annotation = |
| 2279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2280 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2281 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2282 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2283 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2284 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2285 | |
| 2286 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2287 | ASSERT_TRUE(response1); |
| 2288 | ASSERT_TRUE(response1->headers); |
| 2289 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2290 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2291 | |
| 2292 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2293 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2294 | EXPECT_EQ("This server is borked.", response_data1); |
| 2295 | // Deleting the transaction attempts to release the socket back into the |
| 2296 | // socket pool. |
| 2297 | trans1.reset(); |
| 2298 | |
| 2299 | HttpRequestInfo request2; |
| 2300 | request2.method = "GET"; |
| 2301 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2302 | request2.traffic_annotation = |
| 2303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2304 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2305 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2306 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2307 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2308 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2309 | |
| 2310 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2311 | ASSERT_TRUE(response2); |
| 2312 | ASSERT_TRUE(response2->headers); |
| 2313 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2314 | |
| 2315 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2316 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2317 | EXPECT_EQ("foo", response_data2); |
| 2318 | } |
| 2319 | |
| 2320 | // This is a little different from the others - it tests the case that the |
| 2321 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2322 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2323 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2324 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2326 | MockWrite data_writes1[] = { |
| 2327 | MockWrite("GET / HTTP/1.1\r\n" |
| 2328 | "Host: www.borked.com\r\n" |
| 2329 | "Connection: keep-alive\r\n\r\n"), |
| 2330 | }; |
| 2331 | |
| 2332 | MockRead data_reads1[] = { |
| 2333 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2334 | "Connection: keep-alive\r\n" |
| 2335 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2336 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2337 | MockRead("0\r\n\r\nBonus data!"), |
| 2338 | }; |
| 2339 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2340 | data_writes1, arraysize(data_writes1)); |
| 2341 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2342 | |
| 2343 | TestCompletionCallback callback; |
| 2344 | HttpRequestInfo request1; |
| 2345 | request1.method = "GET"; |
| 2346 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2347 | request1.traffic_annotation = |
| 2348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2349 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2350 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2351 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2352 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2353 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2354 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2355 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2356 | ASSERT_TRUE(response1); |
| 2357 | ASSERT_TRUE(response1->headers); |
| 2358 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2359 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2360 | |
| 2361 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2362 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2363 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2364 | |
| 2365 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2366 | // socket can't be reused, rather than returning it to the socket pool. |
| 2367 | base::RunLoop().RunUntilIdle(); |
| 2368 | |
| 2369 | // There should be no idle sockets in the pool. |
| 2370 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2371 | } |
| 2372 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | // Test the request-challenge-retry sequence for basic auth. |
| 2374 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2375 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2376 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2377 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2378 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2379 | request.traffic_annotation = |
| 2380 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2381 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2382 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2383 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2385 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2386 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2387 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2388 | MockWrite( |
| 2389 | "GET / HTTP/1.1\r\n" |
| 2390 | "Host: www.example.org\r\n" |
| 2391 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2392 | }; |
| 2393 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2394 | MockRead data_reads1[] = { |
| 2395 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2396 | // Give a couple authenticate options (only the middle one is actually |
| 2397 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2398 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2399 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2400 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2402 | // Large content-length -- won't matter, as connection will be reset. |
| 2403 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2404 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2405 | }; |
| 2406 | |
| 2407 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2408 | // be issuing -- the final header line contains the credentials. |
| 2409 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2410 | MockWrite( |
| 2411 | "GET / HTTP/1.1\r\n" |
| 2412 | "Host: www.example.org\r\n" |
| 2413 | "Connection: keep-alive\r\n" |
| 2414 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2415 | }; |
| 2416 | |
| 2417 | // Lastly, the server responds with the actual content. |
| 2418 | MockRead data_reads2[] = { |
| 2419 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2421 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | }; |
| 2424 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2425 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2426 | data_writes1, arraysize(data_writes1)); |
| 2427 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2428 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2429 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2430 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2432 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2434 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2436 | |
| 2437 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2438 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2439 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2440 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2441 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2442 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2443 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2444 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2445 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2446 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2447 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2449 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2450 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2451 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2453 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2454 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2455 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2457 | |
| 2458 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2460 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2461 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2462 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2463 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2464 | // The load timing after restart should have a new socket ID, and times after |
| 2465 | // those of the first load timing. |
| 2466 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2467 | load_timing_info2.connect_timing.connect_start); |
| 2468 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2469 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2470 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2471 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2472 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2473 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2475 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2476 | ASSERT_TRUE(response); |
| 2477 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2478 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2479 | } |
| 2480 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2481 | // Test the request-challenge-retry sequence for basic auth. |
| 2482 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2483 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2484 | HttpRequestInfo request; |
| 2485 | request.method = "GET"; |
| 2486 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2487 | request.traffic_annotation = |
| 2488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2489 | |
| 2490 | TestNetLog log; |
| 2491 | MockHostResolver* resolver = new MockHostResolver(); |
| 2492 | session_deps_.net_log = &log; |
| 2493 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2494 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2496 | |
| 2497 | resolver->rules()->ClearRules(); |
| 2498 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2499 | |
| 2500 | MockWrite data_writes1[] = { |
| 2501 | MockWrite("GET / HTTP/1.1\r\n" |
| 2502 | "Host: www.example.org\r\n" |
| 2503 | "Connection: keep-alive\r\n\r\n"), |
| 2504 | }; |
| 2505 | |
| 2506 | MockRead data_reads1[] = { |
| 2507 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2508 | // Give a couple authenticate options (only the middle one is actually |
| 2509 | // supported). |
| 2510 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2511 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2512 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2513 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2514 | // Large content-length -- won't matter, as connection will be reset. |
| 2515 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2516 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2517 | }; |
| 2518 | |
| 2519 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2520 | // be issuing -- the final header line contains the credentials. |
| 2521 | MockWrite data_writes2[] = { |
| 2522 | MockWrite("GET / HTTP/1.1\r\n" |
| 2523 | "Host: www.example.org\r\n" |
| 2524 | "Connection: keep-alive\r\n" |
| 2525 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2526 | }; |
| 2527 | |
| 2528 | // Lastly, the server responds with the actual content. |
| 2529 | MockRead data_reads2[] = { |
| 2530 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2531 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2532 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2533 | }; |
| 2534 | |
| 2535 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2536 | data_writes1, arraysize(data_writes1)); |
| 2537 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2538 | data_writes2, arraysize(data_writes2)); |
| 2539 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2540 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2541 | |
| 2542 | TestCompletionCallback callback1; |
| 2543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2544 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2545 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2546 | |
| 2547 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2548 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2549 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2550 | |
| 2551 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2552 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2553 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2556 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2557 | ASSERT_TRUE(response); |
| 2558 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2559 | |
| 2560 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2561 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2562 | ASSERT_FALSE(endpoint.address().empty()); |
| 2563 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2564 | |
| 2565 | resolver->rules()->ClearRules(); |
| 2566 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2567 | |
| 2568 | TestCompletionCallback callback2; |
| 2569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2570 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2571 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2572 | |
| 2573 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2574 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2575 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2576 | // The load timing after restart should have a new socket ID, and times after |
| 2577 | // those of the first load timing. |
| 2578 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2579 | load_timing_info2.connect_timing.connect_start); |
| 2580 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2581 | |
| 2582 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2583 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2584 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2585 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2587 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2588 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2589 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2590 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2592 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2593 | ASSERT_FALSE(endpoint.address().empty()); |
| 2594 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2595 | } |
| 2596 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2597 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2598 | // will eventually give up. |
| 2599 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2600 | HttpRequestInfo request; |
| 2601 | request.method = "GET"; |
| 2602 | request.url = GURL("http://www.example.org/"); |
| 2603 | request.traffic_annotation = |
| 2604 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2605 | |
| 2606 | TestNetLog log; |
| 2607 | session_deps_.net_log = &log; |
| 2608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2609 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2610 | |
| 2611 | MockWrite data_writes[] = { |
| 2612 | MockWrite("GET / HTTP/1.1\r\n" |
| 2613 | "Host: www.example.org\r\n" |
| 2614 | "Connection: keep-alive\r\n\r\n"), |
| 2615 | }; |
| 2616 | |
| 2617 | MockRead data_reads[] = { |
| 2618 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2619 | // Give a couple authenticate options (only the middle one is actually |
| 2620 | // supported). |
| 2621 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2622 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2623 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2624 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2625 | // Large content-length -- won't matter, as connection will be reset. |
| 2626 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2627 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2628 | }; |
| 2629 | |
| 2630 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2631 | // be issuing -- the final header line contains the credentials. |
| 2632 | MockWrite data_writes_restart[] = { |
| 2633 | MockWrite("GET / HTTP/1.1\r\n" |
| 2634 | "Host: www.example.org\r\n" |
| 2635 | "Connection: keep-alive\r\n" |
| 2636 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2637 | }; |
| 2638 | |
| 2639 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 2640 | arraysize(data_writes)); |
| 2641 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2642 | |
| 2643 | TestCompletionCallback callback; |
| 2644 | int rv = callback.GetResult( |
| 2645 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2646 | |
| 2647 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2648 | for (int i = 0; i < 32; i++) { |
| 2649 | // Check the previous response was a 401. |
| 2650 | EXPECT_THAT(rv, IsOk()); |
| 2651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2652 | ASSERT_TRUE(response); |
| 2653 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2654 | |
| 2655 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
| 2656 | data_reads, arraysize(data_reads), data_writes_restart, |
| 2657 | arraysize(data_writes_restart))); |
| 2658 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2659 | data_restarts.back().get()); |
| 2660 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2661 | callback.callback())); |
| 2662 | } |
| 2663 | |
| 2664 | // After too many tries, the transaction should have given up. |
| 2665 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2666 | } |
| 2667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2668 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2669 | HttpRequestInfo request; |
| 2670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2671 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2672 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2673 | request.traffic_annotation = |
| 2674 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2678 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2679 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2680 | MockWrite( |
| 2681 | "GET / HTTP/1.1\r\n" |
| 2682 | "Host: www.example.org\r\n" |
| 2683 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2684 | }; |
| 2685 | |
| 2686 | MockRead data_reads[] = { |
| 2687 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2688 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2689 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2690 | // Large content-length -- won't matter, as connection will be reset. |
| 2691 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2692 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2693 | }; |
| 2694 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2695 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2696 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2698 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2699 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2702 | |
| 2703 | rv = callback.WaitForResult(); |
| 2704 | EXPECT_EQ(0, rv); |
| 2705 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2706 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2707 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2708 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2709 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2711 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2712 | ASSERT_TRUE(response); |
| 2713 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2714 | } |
| 2715 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2716 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2717 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2718 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2719 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2720 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2721 | // reused. See http://crbug.com/544255. |
| 2722 | for (int i = 0; i < 2; ++i) { |
| 2723 | HttpRequestInfo request; |
| 2724 | request.method = "GET"; |
| 2725 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2726 | request.traffic_annotation = |
| 2727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2728 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2729 | TestNetLog log; |
| 2730 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2732 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2733 | MockWrite data_writes[] = { |
| 2734 | MockWrite(ASYNC, 0, |
| 2735 | "GET / HTTP/1.1\r\n" |
| 2736 | "Host: www.example.org\r\n" |
| 2737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2739 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2740 | // be issuing -- the final header line contains the credentials. |
| 2741 | MockWrite(ASYNC, 6, |
| 2742 | "GET / HTTP/1.1\r\n" |
| 2743 | "Host: www.example.org\r\n" |
| 2744 | "Connection: keep-alive\r\n" |
| 2745 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2746 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2748 | MockRead data_reads[] = { |
| 2749 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2750 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2751 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2752 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2753 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2754 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2755 | // Lastly, the server responds with the actual content. |
| 2756 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2757 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2758 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2759 | MockRead(ASYNC, 10, "Hello"), |
| 2760 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2762 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2763 | arraysize(data_writes)); |
| 2764 | data.set_busy_before_sync_reads(true); |
| 2765 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2766 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2767 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2770 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2771 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2772 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2773 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2774 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2775 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2777 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2778 | ASSERT_TRUE(response); |
| 2779 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2781 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2783 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2784 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2785 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2786 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2787 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2789 | TestLoadTimingReused(load_timing_info2); |
| 2790 | // The load timing after restart should have the same socket ID, and times |
| 2791 | // those of the first load timing. |
| 2792 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2793 | load_timing_info2.send_start); |
| 2794 | 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] | 2795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2797 | ASSERT_TRUE(response); |
| 2798 | EXPECT_FALSE(response->auth_challenge); |
| 2799 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2801 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2803 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2804 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2806 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2808 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2809 | } |
| 2810 | |
| 2811 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2812 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2813 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2814 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2815 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2816 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2817 | request.traffic_annotation = |
| 2818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2821 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2822 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2823 | MockWrite("GET / HTTP/1.1\r\n" |
| 2824 | "Host: www.example.org\r\n" |
| 2825 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2827 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2828 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2829 | MockWrite("GET / HTTP/1.1\r\n" |
| 2830 | "Host: www.example.org\r\n" |
| 2831 | "Connection: keep-alive\r\n" |
| 2832 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2833 | }; |
| 2834 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2835 | MockRead data_reads1[] = { |
| 2836 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2837 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2838 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2839 | |
| 2840 | // Lastly, the server responds with the actual content. |
| 2841 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2842 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2843 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2844 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2845 | }; |
| 2846 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2847 | // An incorrect reconnect would cause this to be read. |
| 2848 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2849 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2850 | }; |
| 2851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2852 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2853 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2854 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2855 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2856 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2857 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2858 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2859 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2862 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2864 | |
| 2865 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2868 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2869 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2870 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2872 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2874 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2876 | |
| 2877 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2878 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2880 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2881 | ASSERT_TRUE(response); |
| 2882 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2883 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2887 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2888 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2889 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2891 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2892 | request.traffic_annotation = |
| 2893 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2894 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2895 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2896 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2897 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2898 | MockWrite("GET / HTTP/1.1\r\n" |
| 2899 | "Host: www.example.org\r\n" |
| 2900 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2902 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2903 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2904 | MockWrite("GET / HTTP/1.1\r\n" |
| 2905 | "Host: www.example.org\r\n" |
| 2906 | "Connection: keep-alive\r\n" |
| 2907 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2908 | }; |
| 2909 | |
| 2910 | // Respond with 5 kb of response body. |
| 2911 | std::string large_body_string("Unauthorized"); |
| 2912 | large_body_string.append(5 * 1024, ' '); |
| 2913 | large_body_string.append("\r\n"); |
| 2914 | |
| 2915 | MockRead data_reads1[] = { |
| 2916 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2917 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2918 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2919 | // 5134 = 12 + 5 * 1024 + 2 |
| 2920 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2921 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | |
| 2923 | // Lastly, the server responds with the actual content. |
| 2924 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2925 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2926 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2927 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2928 | }; |
| 2929 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2930 | // An incorrect reconnect would cause this to be read. |
| 2931 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2932 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2933 | }; |
| 2934 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2935 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2936 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2937 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2938 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2939 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2940 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2942 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2945 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2947 | |
| 2948 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2952 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2953 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2955 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2957 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2959 | |
| 2960 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2963 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2964 | ASSERT_TRUE(response); |
| 2965 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2966 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2970 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2971 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2972 | HttpRequestInfo request; |
| 2973 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2974 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2975 | request.traffic_annotation = |
| 2976 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2979 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2980 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2981 | MockWrite( |
| 2982 | "GET / HTTP/1.1\r\n" |
| 2983 | "Host: www.example.org\r\n" |
| 2984 | "Connection: keep-alive\r\n\r\n"), |
| 2985 | // This simulates the seemingly successful write to a closed connection |
| 2986 | // if the bug is not fixed. |
| 2987 | MockWrite( |
| 2988 | "GET / HTTP/1.1\r\n" |
| 2989 | "Host: www.example.org\r\n" |
| 2990 | "Connection: keep-alive\r\n" |
| 2991 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2992 | }; |
| 2993 | |
| 2994 | MockRead data_reads1[] = { |
| 2995 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2996 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2997 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2998 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2999 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3000 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3001 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3002 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3003 | }; |
| 3004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3005 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3006 | // be issuing -- the final header line contains the credentials. |
| 3007 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3008 | MockWrite( |
| 3009 | "GET / HTTP/1.1\r\n" |
| 3010 | "Host: www.example.org\r\n" |
| 3011 | "Connection: keep-alive\r\n" |
| 3012 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3013 | }; |
| 3014 | |
| 3015 | // Lastly, the server responds with the actual content. |
| 3016 | MockRead data_reads2[] = { |
| 3017 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3019 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3020 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3021 | }; |
| 3022 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3023 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3024 | data_writes1, arraysize(data_writes1)); |
| 3025 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3026 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3027 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3028 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3030 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3033 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3035 | |
| 3036 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3037 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3039 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3040 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3041 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3043 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3045 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3047 | |
| 3048 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3049 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3051 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3052 | ASSERT_TRUE(response); |
| 3053 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3054 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3055 | } |
| 3056 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3057 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3058 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3059 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3060 | HttpRequestInfo request; |
| 3061 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3062 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3063 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3064 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3065 | request.traffic_annotation = |
| 3066 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3067 | |
| 3068 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3069 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3070 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3071 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3072 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3073 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3075 | |
| 3076 | // Since we have proxy, should try to establish tunnel. |
| 3077 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3078 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3079 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3080 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3081 | }; |
| 3082 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3083 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3084 | // connection. |
| 3085 | MockRead data_reads1[] = { |
| 3086 | // No credentials. |
| 3087 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3088 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3089 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3090 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3091 | // Since the first connection couldn't be reused, need to establish another |
| 3092 | // once given credentials. |
| 3093 | MockWrite data_writes2[] = { |
| 3094 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3095 | // be issuing -- the final header line contains the credentials. |
| 3096 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3097 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3098 | "Proxy-Connection: keep-alive\r\n" |
| 3099 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3100 | |
| 3101 | MockWrite("GET / HTTP/1.1\r\n" |
| 3102 | "Host: www.example.org\r\n" |
| 3103 | "Connection: keep-alive\r\n\r\n"), |
| 3104 | }; |
| 3105 | |
| 3106 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3107 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3108 | |
| 3109 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3110 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3111 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3112 | MockRead(SYNCHRONOUS, "hello"), |
| 3113 | }; |
| 3114 | |
| 3115 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3116 | data_writes1, arraysize(data_writes1)); |
| 3117 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3118 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3119 | data_writes2, arraysize(data_writes2)); |
| 3120 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3121 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3123 | |
| 3124 | TestCompletionCallback callback1; |
| 3125 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3128 | |
| 3129 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3131 | |
| 3132 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3133 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3134 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3135 | log.GetEntries(&entries); |
| 3136 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3137 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3138 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3139 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3140 | entries, pos, |
| 3141 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3142 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3143 | |
| 3144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3145 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3146 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3147 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3148 | EXPECT_EQ(407, response->headers->response_code()); |
| 3149 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3150 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3151 | |
| 3152 | LoadTimingInfo load_timing_info; |
| 3153 | // CONNECT requests and responses are handled at the connect job level, so |
| 3154 | // the transaction does not yet have a connection. |
| 3155 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3156 | |
| 3157 | TestCompletionCallback callback2; |
| 3158 | |
| 3159 | rv = |
| 3160 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3162 | |
| 3163 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3164 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3165 | |
| 3166 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3167 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3168 | |
| 3169 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3170 | EXPECT_EQ(200, response->headers->response_code()); |
| 3171 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3172 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3173 | |
| 3174 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3175 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3176 | |
| 3177 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3178 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3179 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3180 | |
| 3181 | trans.reset(); |
| 3182 | session->CloseAllConnections(); |
| 3183 | } |
| 3184 | |
| 3185 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3186 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3187 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3188 | HttpRequestInfo request; |
| 3189 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3190 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3191 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3192 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3193 | request.traffic_annotation = |
| 3194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3195 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3196 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3197 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3198 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3199 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3200 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3201 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3203 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3204 | // Since we have proxy, should try to establish tunnel. |
| 3205 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3206 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3207 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3208 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3209 | }; |
| 3210 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3211 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3212 | // connection. |
| 3213 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3214 | // No credentials. |
| 3215 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3216 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3217 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3218 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3219 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3220 | MockWrite data_writes2[] = { |
| 3221 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3222 | // be issuing -- the final header line contains the credentials. |
| 3223 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3224 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3225 | "Proxy-Connection: keep-alive\r\n" |
| 3226 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3227 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3228 | MockWrite("GET / HTTP/1.1\r\n" |
| 3229 | "Host: www.example.org\r\n" |
| 3230 | "Connection: keep-alive\r\n\r\n"), |
| 3231 | }; |
| 3232 | |
| 3233 | MockRead data_reads2[] = { |
| 3234 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3235 | |
| 3236 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3237 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3238 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3239 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3240 | }; |
| 3241 | |
| 3242 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3243 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3244 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3245 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3246 | data_writes2, arraysize(data_writes2)); |
| 3247 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3248 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3251 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3252 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3253 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3254 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3256 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3258 | |
| 3259 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3260 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3261 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3262 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3263 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3264 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3265 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3266 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3267 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3268 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3269 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3270 | |
| 3271 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3272 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3274 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3275 | EXPECT_EQ(407, response->headers->response_code()); |
| 3276 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3277 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3278 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3279 | LoadTimingInfo load_timing_info; |
| 3280 | // CONNECT requests and responses are handled at the connect job level, so |
| 3281 | // the transaction does not yet have a connection. |
| 3282 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3284 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3285 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3286 | rv = trans->RestartWithAuth( |
| 3287 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3289 | |
| 3290 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3291 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3292 | |
| 3293 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3294 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3295 | |
| 3296 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3297 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3298 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3299 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3300 | |
| 3301 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3302 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3303 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3304 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3305 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3306 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3307 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3308 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3309 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3310 | } |
| 3311 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3312 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3313 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3314 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3315 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3316 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3317 | // reused. See http://crbug.com/544255. |
| 3318 | for (int i = 0; i < 2; ++i) { |
| 3319 | HttpRequestInfo request; |
| 3320 | request.method = "GET"; |
| 3321 | request.url = GURL("https://www.example.org/"); |
| 3322 | // Ensure that proxy authentication is attempted even |
| 3323 | // when the no authentication data flag is set. |
| 3324 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3325 | request.traffic_annotation = |
| 3326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3327 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3328 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3329 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3330 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3331 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | BoundTestNetLog log; |
| 3333 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3334 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3336 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3338 | // Since we have proxy, should try to establish tunnel. |
| 3339 | MockWrite data_writes1[] = { |
| 3340 | MockWrite(ASYNC, 0, |
| 3341 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3342 | "Host: www.example.org:443\r\n" |
| 3343 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3345 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3346 | // be issuing -- the final header line contains the credentials. |
| 3347 | MockWrite(ASYNC, 3, |
| 3348 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3349 | "Host: www.example.org:443\r\n" |
| 3350 | "Proxy-Connection: keep-alive\r\n" |
| 3351 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3352 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3353 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3354 | // The proxy responds to the connect with a 407, using a persistent |
| 3355 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3356 | MockRead data_reads1[] = { |
| 3357 | // No credentials. |
| 3358 | MockRead(ASYNC, 1, |
| 3359 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3360 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3361 | "Proxy-Connection: keep-alive\r\n" |
| 3362 | "Content-Length: 10\r\n\r\n"), |
| 3363 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3364 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3365 | // Wrong credentials (wrong password). |
| 3366 | MockRead(ASYNC, 4, |
| 3367 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3368 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3369 | "Proxy-Connection: keep-alive\r\n" |
| 3370 | "Content-Length: 10\r\n\r\n"), |
| 3371 | // No response body because the test stops reading here. |
| 3372 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3373 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3374 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3375 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3376 | arraysize(data_writes1)); |
| 3377 | data1.set_busy_before_sync_reads(true); |
| 3378 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3379 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3380 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3382 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3383 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3384 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3385 | TestNetLogEntry::List entries; |
| 3386 | log.GetEntries(&entries); |
| 3387 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3388 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3389 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3390 | ExpectLogContainsSomewhere( |
| 3391 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3392 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3393 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3395 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3396 | ASSERT_TRUE(response); |
| 3397 | ASSERT_TRUE(response->headers); |
| 3398 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3399 | EXPECT_EQ(407, response->headers->response_code()); |
| 3400 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3401 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3402 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3403 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3404 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3405 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3406 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3407 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3408 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3409 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3411 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3412 | ASSERT_TRUE(response); |
| 3413 | ASSERT_TRUE(response->headers); |
| 3414 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3415 | EXPECT_EQ(407, response->headers->response_code()); |
| 3416 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3417 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3418 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3419 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3420 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3421 | // out of scope. |
| 3422 | session->CloseAllConnections(); |
| 3423 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3427 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3428 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3429 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3430 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3431 | // reused. See http://crbug.com/544255. |
| 3432 | for (int i = 0; i < 2; ++i) { |
| 3433 | HttpRequestInfo request; |
| 3434 | request.method = "GET"; |
| 3435 | request.url = GURL("https://www.example.org/"); |
| 3436 | // Ensure that proxy authentication is attempted even |
| 3437 | // when the no authentication data flag is set. |
| 3438 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3439 | request.traffic_annotation = |
| 3440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3441 | |
| 3442 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3443 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3444 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3445 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3446 | BoundTestNetLog log; |
| 3447 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3449 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3450 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3451 | |
| 3452 | // Since we have proxy, should try to establish tunnel. |
| 3453 | MockWrite data_writes1[] = { |
| 3454 | MockWrite(ASYNC, 0, |
| 3455 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3456 | "Host: www.example.org:443\r\n" |
| 3457 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3458 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3459 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3460 | // be issuing -- the final header line contains the credentials. |
| 3461 | MockWrite(ASYNC, 3, |
| 3462 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3463 | "Host: www.example.org:443\r\n" |
| 3464 | "Proxy-Connection: keep-alive\r\n" |
| 3465 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3466 | }; |
| 3467 | |
| 3468 | // The proxy responds to the connect with a 407, using a persistent |
| 3469 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3470 | MockRead data_reads1[] = { |
| 3471 | // No credentials. |
| 3472 | MockRead(ASYNC, 1, |
| 3473 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3474 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3475 | "Content-Length: 10\r\n\r\n"), |
| 3476 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3477 | |
| 3478 | // Wrong credentials (wrong password). |
| 3479 | MockRead(ASYNC, 4, |
| 3480 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3481 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3482 | "Content-Length: 10\r\n\r\n"), |
| 3483 | // No response body because the test stops reading here. |
| 3484 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3485 | }; |
| 3486 | |
| 3487 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3488 | arraysize(data_writes1)); |
| 3489 | data1.set_busy_before_sync_reads(true); |
| 3490 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3491 | |
| 3492 | TestCompletionCallback callback1; |
| 3493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3494 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3495 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3496 | |
| 3497 | TestNetLogEntry::List entries; |
| 3498 | log.GetEntries(&entries); |
| 3499 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3500 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3501 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3502 | ExpectLogContainsSomewhere( |
| 3503 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3504 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3505 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3507 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3508 | ASSERT_TRUE(response); |
| 3509 | ASSERT_TRUE(response->headers); |
| 3510 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3511 | EXPECT_EQ(407, response->headers->response_code()); |
| 3512 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3513 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3514 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3515 | |
| 3516 | TestCompletionCallback callback2; |
| 3517 | |
| 3518 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3519 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3520 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3521 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3523 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | ASSERT_TRUE(response); |
| 3525 | ASSERT_TRUE(response->headers); |
| 3526 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3527 | EXPECT_EQ(407, response->headers->response_code()); |
| 3528 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3529 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3530 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3531 | |
| 3532 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3533 | // out of scope. |
| 3534 | session->CloseAllConnections(); |
| 3535 | } |
| 3536 | } |
| 3537 | |
| 3538 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3539 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3540 | // the case the server sends extra data on the original socket, so it can't be |
| 3541 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3542 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3543 | HttpRequestInfo request; |
| 3544 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3545 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3546 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3547 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3548 | request.traffic_annotation = |
| 3549 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3550 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3551 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3552 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3553 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3554 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3555 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3556 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3558 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3559 | // Since we have proxy, should try to establish tunnel. |
| 3560 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3561 | MockWrite(ASYNC, 0, |
| 3562 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3563 | "Host: www.example.org:443\r\n" |
| 3564 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3565 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3566 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3567 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3568 | // extra data, so the socket cannot be reused. |
| 3569 | MockRead data_reads1[] = { |
| 3570 | // No credentials. |
| 3571 | MockRead(ASYNC, 1, |
| 3572 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3573 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3574 | "Content-Length: 10\r\n\r\n"), |
| 3575 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3576 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3577 | }; |
| 3578 | |
| 3579 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3580 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3581 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3582 | MockWrite(ASYNC, 0, |
| 3583 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3584 | "Host: www.example.org:443\r\n" |
| 3585 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3586 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3587 | |
| 3588 | MockWrite(ASYNC, 2, |
| 3589 | "GET / HTTP/1.1\r\n" |
| 3590 | "Host: www.example.org\r\n" |
| 3591 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3592 | }; |
| 3593 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3594 | MockRead data_reads2[] = { |
| 3595 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3596 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3597 | MockRead(ASYNC, 3, |
| 3598 | "HTTP/1.1 200 OK\r\n" |
| 3599 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3600 | "Content-Length: 5\r\n\r\n"), |
| 3601 | // No response body because the test stops reading here. |
| 3602 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3603 | }; |
| 3604 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3606 | arraysize(data_writes1)); |
| 3607 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3608 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3609 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3610 | arraysize(data_writes2)); |
| 3611 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3612 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3614 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3615 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3616 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3617 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3618 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3619 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3621 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3622 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3623 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3624 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3625 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3626 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3627 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3628 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3629 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3630 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3631 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3632 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3633 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3634 | ASSERT_TRUE(response); |
| 3635 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3636 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3637 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3638 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3639 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3640 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3641 | LoadTimingInfo load_timing_info; |
| 3642 | // CONNECT requests and responses are handled at the connect job level, so |
| 3643 | // the transaction does not yet have a connection. |
| 3644 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3646 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3647 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3648 | rv = |
| 3649 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3650 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3651 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3652 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3653 | EXPECT_EQ(200, response->headers->response_code()); |
| 3654 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3655 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3656 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | // The password prompt info should not be set. |
| 3658 | EXPECT_FALSE(response->auth_challenge); |
| 3659 | |
| 3660 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3661 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3662 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3663 | |
| 3664 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3665 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3666 | } |
| 3667 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3668 | // Test the case a proxy closes a socket while the challenge body is being |
| 3669 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3670 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3671 | HttpRequestInfo request; |
| 3672 | request.method = "GET"; |
| 3673 | request.url = GURL("https://www.example.org/"); |
| 3674 | // Ensure that proxy authentication is attempted even |
| 3675 | // when the no authentication data flag is set. |
| 3676 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3677 | request.traffic_annotation = |
| 3678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3679 | |
| 3680 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3681 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3682 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3683 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3686 | |
| 3687 | // Since we have proxy, should try to establish tunnel. |
| 3688 | MockWrite data_writes1[] = { |
| 3689 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3690 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3691 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3692 | }; |
| 3693 | |
| 3694 | // The proxy responds to the connect with a 407, using a persistent |
| 3695 | // connection. |
| 3696 | MockRead data_reads1[] = { |
| 3697 | // No credentials. |
| 3698 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3699 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3700 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3701 | // Server hands up in the middle of the body. |
| 3702 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3703 | }; |
| 3704 | |
| 3705 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3706 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3707 | // be issuing -- the final header line contains the credentials. |
| 3708 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3709 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3710 | "Proxy-Connection: keep-alive\r\n" |
| 3711 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3712 | |
| 3713 | MockWrite("GET / HTTP/1.1\r\n" |
| 3714 | "Host: www.example.org\r\n" |
| 3715 | "Connection: keep-alive\r\n\r\n"), |
| 3716 | }; |
| 3717 | |
| 3718 | MockRead data_reads2[] = { |
| 3719 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3720 | |
| 3721 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3722 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3723 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3724 | MockRead(SYNCHRONOUS, "hello"), |
| 3725 | }; |
| 3726 | |
| 3727 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3728 | data_writes1, arraysize(data_writes1)); |
| 3729 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3730 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3731 | data_writes2, arraysize(data_writes2)); |
| 3732 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3733 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3734 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3735 | |
| 3736 | TestCompletionCallback callback; |
| 3737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3739 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3741 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3742 | ASSERT_TRUE(response); |
| 3743 | ASSERT_TRUE(response->headers); |
| 3744 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3745 | EXPECT_EQ(407, response->headers->response_code()); |
| 3746 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3748 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3749 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3751 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3752 | ASSERT_TRUE(response); |
| 3753 | ASSERT_TRUE(response->headers); |
| 3754 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3755 | EXPECT_EQ(200, response->headers->response_code()); |
| 3756 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3757 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3758 | EXPECT_EQ("hello", body); |
| 3759 | } |
| 3760 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3761 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3762 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3763 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3764 | HttpRequestInfo request; |
| 3765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3766 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3767 | request.traffic_annotation = |
| 3768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3769 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3770 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3771 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3772 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3777 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3778 | // Since we have proxy, should try to establish tunnel. |
| 3779 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3780 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3781 | "Host: www.example.org:443\r\n" |
| 3782 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3783 | }; |
| 3784 | |
| 3785 | // The proxy responds to the connect with a 407. |
| 3786 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3787 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3788 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3789 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3790 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3791 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3792 | }; |
| 3793 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3794 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3795 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3798 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3800 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3802 | |
| 3803 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3804 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3806 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3807 | ASSERT_TRUE(response); |
| 3808 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3809 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3810 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3811 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3812 | |
| 3813 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3814 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3815 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3816 | |
| 3817 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3818 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3819 | } |
| 3820 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3821 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3822 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3823 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3824 | HttpRequestInfo request; |
| 3825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3826 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3827 | request.traffic_annotation = |
| 3828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3829 | |
| 3830 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3831 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3832 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3833 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3836 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3837 | |
| 3838 | // Since we have proxy, should try to establish tunnel. |
| 3839 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3840 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3841 | "Host: www.example.org:443\r\n" |
| 3842 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3843 | }; |
| 3844 | |
| 3845 | // The proxy responds to the connect with a 407. |
| 3846 | MockRead data_reads[] = { |
| 3847 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3848 | MockRead("X-Foo: bar\r\n"), |
| 3849 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3850 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3851 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3852 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3853 | }; |
| 3854 | |
| 3855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3856 | arraysize(data_writes)); |
| 3857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3858 | |
| 3859 | TestCompletionCallback callback; |
| 3860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3861 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3863 | |
| 3864 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3865 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3867 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3868 | ASSERT_TRUE(response); |
| 3869 | ASSERT_TRUE(response->headers); |
| 3870 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3871 | EXPECT_EQ(407, response->headers->response_code()); |
| 3872 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3873 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3874 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3875 | |
| 3876 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3877 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3878 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3879 | |
| 3880 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3881 | session->CloseAllConnections(); |
| 3882 | } |
| 3883 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3884 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3885 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3886 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3887 | HttpRequestInfo request; |
| 3888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3889 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3890 | request.traffic_annotation = |
| 3891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3892 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3893 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3896 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3897 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3898 | MockWrite( |
| 3899 | "GET / HTTP/1.1\r\n" |
| 3900 | "Host: www.example.org\r\n" |
| 3901 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3902 | }; |
| 3903 | |
| 3904 | MockRead data_reads1[] = { |
| 3905 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3906 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3907 | // Large content-length -- won't matter, as connection will be reset. |
| 3908 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3909 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3910 | }; |
| 3911 | |
| 3912 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3913 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3914 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3916 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3920 | |
| 3921 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3922 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3923 | } |
| 3924 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3925 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3926 | // through a non-authenticating proxy. The request should fail with |
| 3927 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3928 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3929 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3930 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3931 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3932 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3933 | HttpRequestInfo request; |
| 3934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3935 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3936 | request.traffic_annotation = |
| 3937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3938 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3939 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3940 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3941 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3942 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3944 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3945 | // Since we have proxy, should try to establish tunnel. |
| 3946 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3947 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3948 | "Host: www.example.org:443\r\n" |
| 3949 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3950 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3951 | MockWrite("GET / HTTP/1.1\r\n" |
| 3952 | "Host: www.example.org\r\n" |
| 3953 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3954 | }; |
| 3955 | |
| 3956 | MockRead data_reads1[] = { |
| 3957 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3958 | |
| 3959 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3960 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3961 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3962 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3963 | }; |
| 3964 | |
| 3965 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3966 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3967 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3968 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3970 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3971 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3972 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3973 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3975 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3977 | |
| 3978 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3979 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3980 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3981 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3982 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3983 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3984 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3985 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3986 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3987 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3988 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3989 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3990 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3991 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3992 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3993 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3994 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3995 | HttpRequestInfo request; |
| 3996 | request.method = "GET"; |
| 3997 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3998 | request.traffic_annotation = |
| 3999 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4000 | |
| 4001 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4002 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4003 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4004 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4005 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4006 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4007 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4008 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4009 | mock_handler->set_allows_default_credentials(true); |
| 4010 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4011 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4012 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4013 | |
| 4014 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4015 | NetLog net_log; |
| 4016 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4017 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4018 | |
| 4019 | // Since we have proxy, should try to establish tunnel. |
| 4020 | MockWrite data_writes1[] = { |
| 4021 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4022 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4023 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4024 | }; |
| 4025 | |
| 4026 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4027 | // connection. |
| 4028 | MockRead data_reads1[] = { |
| 4029 | // No credentials. |
| 4030 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4031 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4032 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4033 | }; |
| 4034 | |
| 4035 | // Since the first connection couldn't be reused, need to establish another |
| 4036 | // once given credentials. |
| 4037 | MockWrite data_writes2[] = { |
| 4038 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4039 | // be issuing -- the final header line contains the credentials. |
| 4040 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4041 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4042 | "Proxy-Connection: keep-alive\r\n" |
| 4043 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4044 | |
| 4045 | MockWrite("GET / HTTP/1.1\r\n" |
| 4046 | "Host: www.example.org\r\n" |
| 4047 | "Connection: keep-alive\r\n\r\n"), |
| 4048 | }; |
| 4049 | |
| 4050 | MockRead data_reads2[] = { |
| 4051 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4052 | |
| 4053 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4054 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4055 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4056 | MockRead(SYNCHRONOUS, "hello"), |
| 4057 | }; |
| 4058 | |
| 4059 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4060 | data_writes1, arraysize(data_writes1)); |
| 4061 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4062 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4063 | data_writes2, arraysize(data_writes2)); |
| 4064 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4065 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4066 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4067 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4068 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4069 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4070 | |
| 4071 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4072 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4073 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4074 | |
| 4075 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4076 | ASSERT_TRUE(response); |
| 4077 | ASSERT_TRUE(response->headers); |
| 4078 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4079 | EXPECT_EQ(407, response->headers->response_code()); |
| 4080 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4081 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4082 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4083 | |
| 4084 | LoadTimingInfo load_timing_info; |
| 4085 | // CONNECT requests and responses are handled at the connect job level, so |
| 4086 | // the transaction does not yet have a connection. |
| 4087 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4088 | |
| 4089 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4090 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4091 | response = trans->GetResponseInfo(); |
| 4092 | ASSERT_TRUE(response); |
| 4093 | ASSERT_TRUE(response->headers); |
| 4094 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4095 | EXPECT_EQ(200, response->headers->response_code()); |
| 4096 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4097 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4098 | |
| 4099 | // The password prompt info should not be set. |
| 4100 | EXPECT_FALSE(response->auth_challenge); |
| 4101 | |
| 4102 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4103 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4104 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4105 | |
| 4106 | trans.reset(); |
| 4107 | session->CloseAllConnections(); |
| 4108 | } |
| 4109 | |
| 4110 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4111 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4112 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4113 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4114 | HttpRequestInfo request; |
| 4115 | request.method = "GET"; |
| 4116 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4117 | request.traffic_annotation = |
| 4118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4119 | |
| 4120 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4121 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4122 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4123 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4124 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4125 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4126 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4127 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4128 | mock_handler->set_allows_default_credentials(true); |
| 4129 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4130 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4131 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4132 | |
| 4133 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4134 | NetLog net_log; |
| 4135 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4136 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4137 | |
| 4138 | // Should try to establish tunnel. |
| 4139 | MockWrite data_writes1[] = { |
| 4140 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4141 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4142 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4143 | |
| 4144 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4145 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4146 | "Proxy-Connection: keep-alive\r\n" |
| 4147 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4148 | }; |
| 4149 | |
| 4150 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4151 | // connection. |
| 4152 | MockRead data_reads1[] = { |
| 4153 | // No credentials. |
| 4154 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4155 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4156 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4157 | }; |
| 4158 | |
| 4159 | // Since the first connection was closed, need to establish another once given |
| 4160 | // credentials. |
| 4161 | MockWrite data_writes2[] = { |
| 4162 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4163 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4164 | "Proxy-Connection: keep-alive\r\n" |
| 4165 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4166 | |
| 4167 | MockWrite("GET / HTTP/1.1\r\n" |
| 4168 | "Host: www.example.org\r\n" |
| 4169 | "Connection: keep-alive\r\n\r\n"), |
| 4170 | }; |
| 4171 | |
| 4172 | MockRead data_reads2[] = { |
| 4173 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4174 | |
| 4175 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4176 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4177 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4178 | MockRead(SYNCHRONOUS, "hello"), |
| 4179 | }; |
| 4180 | |
| 4181 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4182 | data_writes1, arraysize(data_writes1)); |
| 4183 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4184 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4185 | data_writes2, arraysize(data_writes2)); |
| 4186 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4187 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4189 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4190 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4191 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4192 | |
| 4193 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4194 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4195 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4196 | |
| 4197 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4198 | ASSERT_TRUE(response); |
| 4199 | ASSERT_TRUE(response->headers); |
| 4200 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4201 | EXPECT_EQ(407, response->headers->response_code()); |
| 4202 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4203 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4204 | EXPECT_FALSE(response->auth_challenge); |
| 4205 | |
| 4206 | LoadTimingInfo load_timing_info; |
| 4207 | // CONNECT requests and responses are handled at the connect job level, so |
| 4208 | // the transaction does not yet have a connection. |
| 4209 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4210 | |
| 4211 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4212 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4213 | |
| 4214 | response = trans->GetResponseInfo(); |
| 4215 | ASSERT_TRUE(response); |
| 4216 | ASSERT_TRUE(response->headers); |
| 4217 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4218 | EXPECT_EQ(200, response->headers->response_code()); |
| 4219 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4220 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4221 | |
| 4222 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4223 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | |
| 4225 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4226 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4227 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4228 | |
| 4229 | trans.reset(); |
| 4230 | session->CloseAllConnections(); |
| 4231 | } |
| 4232 | |
| 4233 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4234 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4235 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4236 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4237 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4238 | HttpRequestInfo request; |
| 4239 | request.method = "GET"; |
| 4240 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4241 | request.traffic_annotation = |
| 4242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4243 | |
| 4244 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4245 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4246 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4247 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4248 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4249 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4250 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4251 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4252 | mock_handler->set_allows_default_credentials(true); |
| 4253 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4254 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4255 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4256 | |
| 4257 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4258 | NetLog net_log; |
| 4259 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4260 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | |
| 4262 | // Should try to establish tunnel. |
| 4263 | MockWrite data_writes1[] = { |
| 4264 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4265 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4266 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4267 | |
| 4268 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4269 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | "Proxy-Connection: keep-alive\r\n" |
| 4271 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4272 | }; |
| 4273 | |
| 4274 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4275 | // second request is sent. |
| 4276 | MockRead data_reads1[] = { |
| 4277 | // No credentials. |
| 4278 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4279 | MockRead("Content-Length: 0\r\n"), |
| 4280 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4281 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4282 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4283 | }; |
| 4284 | |
| 4285 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4286 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4287 | // request. |
| 4288 | MockWrite data_writes2[] = { |
| 4289 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4290 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4291 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4292 | }; |
| 4293 | |
| 4294 | // The proxy, having had more than enough of us, just hangs up. |
| 4295 | MockRead data_reads2[] = { |
| 4296 | // No credentials. |
| 4297 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4298 | }; |
| 4299 | |
| 4300 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4301 | data_writes1, arraysize(data_writes1)); |
| 4302 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4303 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4304 | data_writes2, arraysize(data_writes2)); |
| 4305 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4306 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4307 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4308 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4309 | |
| 4310 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4311 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4312 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4313 | |
| 4314 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4315 | ASSERT_TRUE(response); |
| 4316 | ASSERT_TRUE(response->headers); |
| 4317 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4318 | EXPECT_EQ(407, response->headers->response_code()); |
| 4319 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4320 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4321 | EXPECT_FALSE(response->auth_challenge); |
| 4322 | |
| 4323 | LoadTimingInfo load_timing_info; |
| 4324 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4325 | |
| 4326 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4327 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4328 | |
| 4329 | trans.reset(); |
| 4330 | session->CloseAllConnections(); |
| 4331 | } |
| 4332 | |
| 4333 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4334 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4335 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4336 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4337 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4338 | HttpRequestInfo request; |
| 4339 | request.method = "GET"; |
| 4340 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4341 | request.traffic_annotation = |
| 4342 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4343 | |
| 4344 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4345 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4346 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4347 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4348 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4349 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4350 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4351 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4352 | mock_handler->set_allows_default_credentials(true); |
| 4353 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4354 | HttpAuth::AUTH_PROXY); |
| 4355 | // Add another handler for the second challenge. It supports default |
| 4356 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4357 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4358 | mock_handler->set_allows_default_credentials(true); |
| 4359 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4360 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4361 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4362 | |
| 4363 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4364 | NetLog net_log; |
| 4365 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4366 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4367 | |
| 4368 | // Should try to establish tunnel. |
| 4369 | MockWrite data_writes1[] = { |
| 4370 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4371 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4372 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4373 | }; |
| 4374 | |
| 4375 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4376 | // connection. |
| 4377 | MockRead data_reads1[] = { |
| 4378 | // No credentials. |
| 4379 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4380 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4381 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4382 | }; |
| 4383 | |
| 4384 | // Since the first connection was closed, need to establish another once given |
| 4385 | // credentials. |
| 4386 | MockWrite data_writes2[] = { |
| 4387 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4388 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4389 | "Proxy-Connection: keep-alive\r\n" |
| 4390 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4391 | }; |
| 4392 | |
| 4393 | MockRead data_reads2[] = { |
| 4394 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4395 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4396 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4397 | }; |
| 4398 | |
| 4399 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4400 | data_writes1, arraysize(data_writes1)); |
| 4401 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4402 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4403 | data_writes2, arraysize(data_writes2)); |
| 4404 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4405 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4407 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4408 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4409 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4410 | |
| 4411 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4412 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4413 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4414 | |
| 4415 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4416 | ASSERT_TRUE(response); |
| 4417 | ASSERT_TRUE(response->headers); |
| 4418 | EXPECT_EQ(407, response->headers->response_code()); |
| 4419 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4420 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4421 | EXPECT_FALSE(response->auth_challenge); |
| 4422 | |
| 4423 | LoadTimingInfo load_timing_info; |
| 4424 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4425 | |
| 4426 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4427 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4428 | response = trans->GetResponseInfo(); |
| 4429 | ASSERT_TRUE(response); |
| 4430 | ASSERT_TRUE(response->headers); |
| 4431 | EXPECT_EQ(407, response->headers->response_code()); |
| 4432 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4433 | EXPECT_TRUE(response->auth_challenge); |
| 4434 | |
| 4435 | trans.reset(); |
| 4436 | session->CloseAllConnections(); |
| 4437 | } |
| 4438 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4439 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4440 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4441 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4442 | // authentication handshake can continue with the same scheme but with a |
| 4443 | // different identity. |
| 4444 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4445 | HttpRequestInfo request; |
| 4446 | request.method = "GET"; |
| 4447 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4448 | request.traffic_annotation = |
| 4449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4450 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4451 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4452 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4453 | |
| 4454 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4455 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4456 | mock_handler->set_allows_default_credentials(true); |
| 4457 | mock_handler->set_allows_explicit_credentials(true); |
| 4458 | mock_handler->set_connection_based(true); |
| 4459 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4460 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4461 | HttpAuth::AUTH_SERVER); |
| 4462 | |
| 4463 | // Add another handler for the second challenge. It supports default |
| 4464 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4465 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4466 | mock_handler->set_allows_default_credentials(true); |
| 4467 | mock_handler->set_allows_explicit_credentials(true); |
| 4468 | mock_handler->set_connection_based(true); |
| 4469 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4470 | HttpAuth::AUTH_SERVER); |
| 4471 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4472 | |
| 4473 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4474 | |
| 4475 | MockWrite data_writes1[] = { |
| 4476 | MockWrite("GET / HTTP/1.1\r\n" |
| 4477 | "Host: www.example.org\r\n" |
| 4478 | "Connection: keep-alive\r\n\r\n"), |
| 4479 | }; |
| 4480 | |
| 4481 | MockRead data_reads1[] = { |
| 4482 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4483 | "WWW-Authenticate: Mock\r\n" |
| 4484 | "Connection: keep-alive\r\n\r\n"), |
| 4485 | }; |
| 4486 | |
| 4487 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4488 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4489 | // transaction procceds without an authorization header. |
| 4490 | MockWrite data_writes2[] = { |
| 4491 | MockWrite("GET / HTTP/1.1\r\n" |
| 4492 | "Host: www.example.org\r\n" |
| 4493 | "Connection: keep-alive\r\n\r\n"), |
| 4494 | }; |
| 4495 | |
| 4496 | MockRead data_reads2[] = { |
| 4497 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4498 | "WWW-Authenticate: Mock\r\n" |
| 4499 | "Connection: keep-alive\r\n\r\n"), |
| 4500 | }; |
| 4501 | |
| 4502 | MockWrite data_writes3[] = { |
| 4503 | MockWrite("GET / HTTP/1.1\r\n" |
| 4504 | "Host: www.example.org\r\n" |
| 4505 | "Connection: keep-alive\r\n" |
| 4506 | "Authorization: auth_token\r\n\r\n"), |
| 4507 | }; |
| 4508 | |
| 4509 | MockRead data_reads3[] = { |
| 4510 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4511 | "Content-Length: 5\r\n" |
| 4512 | "Content-Type: text/plain\r\n" |
| 4513 | "Connection: keep-alive\r\n\r\n" |
| 4514 | "Hello"), |
| 4515 | }; |
| 4516 | |
| 4517 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4518 | data_writes1, arraysize(data_writes1)); |
| 4519 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4520 | |
| 4521 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4522 | data_writes2, arraysize(data_writes2)); |
| 4523 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4524 | |
| 4525 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4526 | data_writes3, arraysize(data_writes3)); |
| 4527 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4528 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4529 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4530 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4531 | |
| 4532 | TestCompletionCallback callback; |
| 4533 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4534 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4535 | |
| 4536 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4537 | ASSERT_TRUE(response); |
| 4538 | ASSERT_TRUE(response->headers); |
| 4539 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4540 | |
| 4541 | // The following three tests assert that an authentication challenge was |
| 4542 | // received and that the stack is ready to respond to the challenge using |
| 4543 | // ambient credentials. |
| 4544 | EXPECT_EQ(401, response->headers->response_code()); |
| 4545 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4546 | EXPECT_FALSE(response->auth_challenge); |
| 4547 | |
| 4548 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4549 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4550 | response = trans->GetResponseInfo(); |
| 4551 | ASSERT_TRUE(response); |
| 4552 | ASSERT_TRUE(response->headers); |
| 4553 | |
| 4554 | // The following three tests assert that an authentication challenge was |
| 4555 | // received and that the stack needs explicit credentials before it is ready |
| 4556 | // to respond to the challenge. |
| 4557 | EXPECT_EQ(401, response->headers->response_code()); |
| 4558 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4559 | EXPECT_TRUE(response->auth_challenge); |
| 4560 | |
| 4561 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4562 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4563 | response = trans->GetResponseInfo(); |
| 4564 | ASSERT_TRUE(response); |
| 4565 | ASSERT_TRUE(response->headers); |
| 4566 | EXPECT_EQ(200, response->headers->response_code()); |
| 4567 | |
| 4568 | trans.reset(); |
| 4569 | session->CloseAllConnections(); |
| 4570 | } |
| 4571 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4572 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4573 | // schemes, based on the path of the URL being requests. |
| 4574 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4575 | public: |
| 4576 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4577 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4578 | |
| 4579 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4580 | |
| 4581 | static HostPortPair ProxyHostPortPair() { |
| 4582 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4583 | } |
| 4584 | |
| 4585 | // ProxyResolver implementation. |
| 4586 | int GetProxyForURL(const GURL& url, |
| 4587 | ProxyInfo* results, |
| 4588 | const CompletionCallback& callback, |
| 4589 | std::unique_ptr<Request>* request, |
| 4590 | const NetLogWithSource& /*net_log*/) override { |
| 4591 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4592 | results->set_traffic_annotation( |
| 4593 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4594 | if (url.path() == "/socks4") { |
| 4595 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4596 | return OK; |
| 4597 | } |
| 4598 | if (url.path() == "/socks5") { |
| 4599 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4600 | return OK; |
| 4601 | } |
| 4602 | if (url.path() == "/http") { |
| 4603 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4604 | return OK; |
| 4605 | } |
| 4606 | if (url.path() == "/https") { |
| 4607 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4608 | return OK; |
| 4609 | } |
| 4610 | NOTREACHED(); |
| 4611 | return ERR_NOT_IMPLEMENTED; |
| 4612 | } |
| 4613 | |
| 4614 | private: |
| 4615 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4616 | }; |
| 4617 | |
| 4618 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4619 | : public ProxyResolverFactory { |
| 4620 | public: |
| 4621 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4622 | : ProxyResolverFactory(false) {} |
| 4623 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4624 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4625 | std::unique_ptr<ProxyResolver>* resolver, |
| 4626 | const CompletionCallback& callback, |
| 4627 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4628 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4629 | return OK; |
| 4630 | } |
| 4631 | |
| 4632 | private: |
| 4633 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4634 | }; |
| 4635 | |
| 4636 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4637 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4638 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4639 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4640 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4641 | session_deps_.proxy_resolution_service = |
| 4642 | std::make_unique<ProxyResolutionService>( |
| 4643 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4644 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4645 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4646 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4647 | |
| 4648 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4649 | |
| 4650 | MockWrite socks_writes[] = { |
| 4651 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4652 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4653 | MockWrite(SYNCHRONOUS, |
| 4654 | "GET /socks4 HTTP/1.1\r\n" |
| 4655 | "Host: test\r\n" |
| 4656 | "Connection: keep-alive\r\n\r\n"), |
| 4657 | }; |
| 4658 | MockRead socks_reads[] = { |
| 4659 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4660 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4661 | "Connection: keep-alive\r\n" |
| 4662 | "Content-Length: 15\r\n\r\n" |
| 4663 | "SOCKS4 Response"), |
| 4664 | }; |
| 4665 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4666 | socks_writes, arraysize(socks_writes)); |
| 4667 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4668 | |
| 4669 | const char kSOCKS5Request[] = { |
| 4670 | 0x05, // Version |
| 4671 | 0x01, // Command (CONNECT) |
| 4672 | 0x00, // Reserved |
| 4673 | 0x03, // Address type (DOMAINNAME) |
| 4674 | 0x04, // Length of domain (4) |
| 4675 | 't', 'e', 's', 't', // Domain string |
| 4676 | 0x00, 0x50, // 16-bit port (80) |
| 4677 | }; |
| 4678 | MockWrite socks5_writes[] = { |
| 4679 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4680 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4681 | MockWrite(SYNCHRONOUS, |
| 4682 | "GET /socks5 HTTP/1.1\r\n" |
| 4683 | "Host: test\r\n" |
| 4684 | "Connection: keep-alive\r\n\r\n"), |
| 4685 | }; |
| 4686 | MockRead socks5_reads[] = { |
| 4687 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4688 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4689 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4690 | "Connection: keep-alive\r\n" |
| 4691 | "Content-Length: 15\r\n\r\n" |
| 4692 | "SOCKS5 Response"), |
| 4693 | }; |
| 4694 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4695 | socks5_writes, arraysize(socks5_writes)); |
| 4696 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4697 | |
| 4698 | MockWrite http_writes[] = { |
| 4699 | MockWrite(SYNCHRONOUS, |
| 4700 | "GET http://test/http HTTP/1.1\r\n" |
| 4701 | "Host: test\r\n" |
| 4702 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4703 | }; |
| 4704 | MockRead http_reads[] = { |
| 4705 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4706 | "Proxy-Connection: keep-alive\r\n" |
| 4707 | "Content-Length: 13\r\n\r\n" |
| 4708 | "HTTP Response"), |
| 4709 | }; |
| 4710 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4711 | http_writes, arraysize(http_writes)); |
| 4712 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4713 | |
| 4714 | MockWrite https_writes[] = { |
| 4715 | MockWrite(SYNCHRONOUS, |
| 4716 | "GET http://test/https HTTP/1.1\r\n" |
| 4717 | "Host: test\r\n" |
| 4718 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4719 | }; |
| 4720 | MockRead https_reads[] = { |
| 4721 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4722 | "Proxy-Connection: keep-alive\r\n" |
| 4723 | "Content-Length: 14\r\n\r\n" |
| 4724 | "HTTPS Response"), |
| 4725 | }; |
| 4726 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4727 | https_writes, arraysize(https_writes)); |
| 4728 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4729 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4730 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4731 | |
| 4732 | struct TestCase { |
| 4733 | GURL url; |
| 4734 | std::string expected_response; |
| 4735 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4736 | // after the test. |
| 4737 | int expected_idle_socks_sockets; |
| 4738 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4739 | // the test. |
| 4740 | int expected_idle_http_sockets; |
| 4741 | } const kTestCases[] = { |
| 4742 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4743 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4744 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4745 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4746 | }; |
| 4747 | |
| 4748 | for (const auto& test_case : kTestCases) { |
| 4749 | HttpRequestInfo request; |
| 4750 | request.method = "GET"; |
| 4751 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4752 | request.traffic_annotation = |
| 4753 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4754 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4755 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4756 | session.get()); |
| 4757 | TestCompletionCallback callback; |
| 4758 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4759 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4760 | |
| 4761 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4762 | ASSERT_TRUE(response); |
| 4763 | ASSERT_TRUE(response->headers); |
| 4764 | EXPECT_EQ(200, response->headers->response_code()); |
| 4765 | std::string response_data; |
| 4766 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4767 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4768 | |
| 4769 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4770 | // the next requests. |
| 4771 | trans.reset(); |
| 4772 | base::RunLoop().RunUntilIdle(); |
| 4773 | |
| 4774 | // Check the number of idle sockets in the pool, to make sure that used |
| 4775 | // sockets are indeed being returned to the socket pool. If each request |
| 4776 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4777 | // pass. |
| 4778 | EXPECT_EQ( |
| 4779 | test_case.expected_idle_socks_sockets, |
| 4780 | session |
| 4781 | ->GetSocketPoolForSOCKSProxy( |
| 4782 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4783 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4784 | ->IdleSocketCount()); |
| 4785 | EXPECT_EQ( |
| 4786 | test_case.expected_idle_http_sockets, |
| 4787 | session |
| 4788 | ->GetSocketPoolForHTTPProxy( |
| 4789 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4790 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4791 | ->IdleSocketCount()); |
| 4792 | } |
| 4793 | } |
| 4794 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4795 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4796 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4797 | HttpRequestInfo request1; |
| 4798 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4799 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4800 | request1.traffic_annotation = |
| 4801 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4802 | |
| 4803 | HttpRequestInfo request2; |
| 4804 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4805 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4806 | request2.traffic_annotation = |
| 4807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4808 | |
| 4809 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4810 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4811 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4812 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4813 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4815 | |
| 4816 | // Since we have proxy, should try to establish tunnel. |
| 4817 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4818 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4819 | "Host: www.example.org:443\r\n" |
| 4820 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4821 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4822 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4823 | "Host: www.example.org\r\n" |
| 4824 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4825 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4826 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4827 | "Host: www.example.org\r\n" |
| 4828 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4829 | }; |
| 4830 | |
| 4831 | // The proxy responds to the connect with a 407, using a persistent |
| 4832 | // connection. |
| 4833 | MockRead data_reads1[] = { |
| 4834 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4835 | |
| 4836 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4837 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4838 | MockRead(SYNCHRONOUS, "1"), |
| 4839 | |
| 4840 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4841 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4842 | MockRead(SYNCHRONOUS, "22"), |
| 4843 | }; |
| 4844 | |
| 4845 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4846 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4847 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4848 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4850 | |
| 4851 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4852 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4853 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4854 | |
| 4855 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4856 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4857 | |
| 4858 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4859 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4860 | |
| 4861 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4862 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4863 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4864 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4865 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4866 | |
| 4867 | LoadTimingInfo load_timing_info1; |
| 4868 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4869 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4870 | |
| 4871 | trans1.reset(); |
| 4872 | |
| 4873 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4874 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4876 | |
| 4877 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4879 | |
| 4880 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4881 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4882 | |
| 4883 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4884 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4885 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4886 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4887 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4888 | |
| 4889 | LoadTimingInfo load_timing_info2; |
| 4890 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4891 | TestLoadTimingReused(load_timing_info2); |
| 4892 | |
| 4893 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4894 | |
| 4895 | trans2.reset(); |
| 4896 | session->CloseAllConnections(); |
| 4897 | } |
| 4898 | |
| 4899 | // 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] | 4900 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4901 | HttpRequestInfo request1; |
| 4902 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4903 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4904 | request1.traffic_annotation = |
| 4905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4906 | |
| 4907 | HttpRequestInfo request2; |
| 4908 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4909 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4910 | request2.traffic_annotation = |
| 4911 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4912 | |
| 4913 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4914 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4915 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4916 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4917 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4918 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4920 | |
| 4921 | // Since we have proxy, should try to establish tunnel. |
| 4922 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4923 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4924 | "Host: www.example.org:443\r\n" |
| 4925 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4926 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4927 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4928 | "Host: www.example.org\r\n" |
| 4929 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4930 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4931 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4932 | "Host: www.example.org\r\n" |
| 4933 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4934 | }; |
| 4935 | |
| 4936 | // The proxy responds to the connect with a 407, using a persistent |
| 4937 | // connection. |
| 4938 | MockRead data_reads1[] = { |
| 4939 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4940 | |
| 4941 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4942 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4943 | MockRead(SYNCHRONOUS, "1"), |
| 4944 | |
| 4945 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4946 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4947 | MockRead(SYNCHRONOUS, "22"), |
| 4948 | }; |
| 4949 | |
| 4950 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4951 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4953 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4955 | |
| 4956 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4957 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4958 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4959 | |
| 4960 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4962 | |
| 4963 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4965 | |
| 4966 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4967 | ASSERT_TRUE(response1); |
| 4968 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4969 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4970 | |
| 4971 | LoadTimingInfo load_timing_info1; |
| 4972 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4973 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4974 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4975 | |
| 4976 | trans1.reset(); |
| 4977 | |
| 4978 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4979 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4980 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4981 | |
| 4982 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4984 | |
| 4985 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4987 | |
| 4988 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4989 | ASSERT_TRUE(response2); |
| 4990 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4991 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4992 | |
| 4993 | LoadTimingInfo load_timing_info2; |
| 4994 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4995 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4996 | |
| 4997 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4998 | |
| 4999 | trans2.reset(); |
| 5000 | session->CloseAllConnections(); |
| 5001 | } |
| 5002 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5003 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5004 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5005 | HttpRequestInfo request; |
| 5006 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5007 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5008 | request.traffic_annotation = |
| 5009 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5010 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5011 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5012 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5013 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5014 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5015 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5017 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5018 | // Since we have proxy, should use full url |
| 5019 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5020 | MockWrite( |
| 5021 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5022 | "Host: www.example.org\r\n" |
| 5023 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5024 | }; |
| 5025 | |
| 5026 | MockRead data_reads1[] = { |
| 5027 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5028 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5029 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5030 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5031 | }; |
| 5032 | |
| 5033 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5034 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5035 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5036 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5037 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5039 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5040 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5041 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5043 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5045 | |
| 5046 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5048 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5049 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5050 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5051 | TestLoadTimingNotReused(load_timing_info, |
| 5052 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5054 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5055 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5056 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5057 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5058 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5059 | EXPECT_EQ(200, response->headers->response_code()); |
| 5060 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5061 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5062 | |
| 5063 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5064 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5065 | } |
| 5066 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5067 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5068 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5069 | HttpRequestInfo request; |
| 5070 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5071 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5072 | request.traffic_annotation = |
| 5073 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5074 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5075 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5076 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5077 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5078 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5079 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5081 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5082 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5083 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5084 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5085 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5086 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5087 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5088 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5089 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5090 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5091 | }; |
| 5092 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5093 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5094 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5095 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5096 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5097 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5098 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5101 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5105 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5107 | |
| 5108 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5109 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5110 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5111 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5112 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5113 | TestLoadTimingNotReused(load_timing_info, |
| 5114 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5117 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5118 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5119 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5120 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5121 | |
| 5122 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5123 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5124 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5125 | } |
| 5126 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5127 | // Verifies that a session which races and wins against the owning transaction |
| 5128 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5129 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5130 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5131 | HttpRequestInfo request; |
| 5132 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5133 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5134 | request.traffic_annotation = |
| 5135 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5136 | |
| 5137 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5138 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5139 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5140 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5141 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5143 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5144 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5145 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5146 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5147 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5148 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5149 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5150 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5151 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5152 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5153 | }; |
| 5154 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5155 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5156 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5157 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5158 | |
| 5159 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5160 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5161 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5162 | |
| 5163 | TestCompletionCallback callback1; |
| 5164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5165 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5166 | |
| 5167 | // Stall the hostname resolution begun by the transaction. |
| 5168 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5169 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5171 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5173 | |
| 5174 | // Race a session to the proxy, which completes first. |
| 5175 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5176 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5177 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5178 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5179 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5180 | |
| 5181 | // Unstall the resolution begun by the transaction. |
| 5182 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5183 | session_deps_.host_resolver->ResolveAllPending(); |
| 5184 | |
| 5185 | EXPECT_FALSE(callback1.have_result()); |
| 5186 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5188 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5189 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5190 | ASSERT_TRUE(response); |
| 5191 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5192 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5193 | |
| 5194 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5195 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5196 | EXPECT_EQ(kUploadData, response_data); |
| 5197 | } |
| 5198 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5199 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5200 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5201 | HttpRequestInfo request; |
| 5202 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5203 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5204 | request.traffic_annotation = |
| 5205 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5206 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5207 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5208 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5209 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5210 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5211 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5212 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5213 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5214 | // The first request will be a bare GET, the second request will be a |
| 5215 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5216 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5217 | SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5218 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5219 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5220 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5221 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5222 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5223 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5224 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5225 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5226 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5227 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5228 | }; |
| 5229 | |
| 5230 | // The first response is a 407 proxy authentication challenge, and the second |
| 5231 | // response will be a 200 response since the second request includes a valid |
| 5232 | // Authorization header. |
| 5233 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5234 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5235 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5236 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5237 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5238 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5239 | SpdySerializedFrame body_authentication( |
| 5240 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5241 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5242 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5243 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5244 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5245 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5246 | CreateMockRead(resp_data, 4), |
| 5247 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5248 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5249 | }; |
| 5250 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5251 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5252 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5253 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5254 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5255 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5256 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5259 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5263 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5265 | |
| 5266 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5268 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5269 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5270 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5271 | ASSERT_TRUE(response); |
| 5272 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5273 | EXPECT_EQ(407, response->headers->response_code()); |
| 5274 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5275 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5277 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5279 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5281 | |
| 5282 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5285 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5286 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5287 | ASSERT_TRUE(response_restart); |
| 5288 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5289 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5290 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5291 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5292 | } |
| 5293 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5294 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5295 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5296 | HttpRequestInfo request; |
| 5297 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5298 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5299 | request.traffic_annotation = |
| 5300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5301 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5302 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5303 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5304 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5305 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5306 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5307 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5309 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5310 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5311 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5312 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5313 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5314 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5315 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5316 | const char get[] = |
| 5317 | "GET / HTTP/1.1\r\n" |
| 5318 | "Host: www.example.org\r\n" |
| 5319 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5320 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5321 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5322 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5323 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5324 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5325 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5326 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5327 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5328 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5329 | SpdySerializedFrame window_update( |
| 5330 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5331 | |
| 5332 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5333 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5334 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5335 | }; |
| 5336 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5337 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5338 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5339 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5340 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5341 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5342 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5343 | }; |
| 5344 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5345 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5346 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5347 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5348 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5349 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5350 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5352 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5355 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5357 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5359 | |
| 5360 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5361 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5362 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5363 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5364 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5365 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5368 | ASSERT_TRUE(response); |
| 5369 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5370 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5371 | |
| 5372 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5373 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5374 | EXPECT_EQ("1234567890", response_data); |
| 5375 | } |
| 5376 | |
| 5377 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5378 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5379 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5380 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5381 | HttpRequestInfo request; |
| 5382 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5383 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5384 | request.traffic_annotation = |
| 5385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5386 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5387 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5388 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5389 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5390 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5391 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5395 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5396 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5397 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5398 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5399 | // fetch https://www.example.org/ via SPDY |
| 5400 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5401 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5402 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5403 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5404 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5405 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5406 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5407 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5408 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5409 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5410 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5411 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5412 | SpdySerializedFrame window_update_get_resp( |
| 5413 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5414 | SpdySerializedFrame window_update_body( |
| 5415 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5416 | |
| 5417 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5418 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5419 | CreateMockWrite(window_update_get_resp, 6), |
| 5420 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5421 | }; |
| 5422 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5423 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5424 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5425 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5426 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5427 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5428 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5429 | }; |
| 5430 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5431 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5432 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5433 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5434 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5435 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5436 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5438 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5439 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5441 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5442 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5444 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5446 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5447 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5448 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5449 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5450 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5451 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5452 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5453 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5454 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5455 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5456 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5459 | ASSERT_TRUE(response); |
| 5460 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5461 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5462 | |
| 5463 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5464 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5465 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5466 | } |
| 5467 | |
| 5468 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5469 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5470 | HttpRequestInfo request; |
| 5471 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5472 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5473 | request.traffic_annotation = |
| 5474 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5475 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5476 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5477 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5478 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5479 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5480 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5484 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5485 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5486 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5487 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5488 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5489 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5490 | |
| 5491 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5492 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5493 | }; |
| 5494 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5495 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5496 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5497 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5498 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5499 | }; |
| 5500 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5501 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5502 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5503 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5504 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5505 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5506 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5508 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5509 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5510 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5512 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5514 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5515 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5516 | |
| 5517 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5518 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5519 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5520 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5521 | } |
| 5522 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5523 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5524 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5525 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5526 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5527 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5528 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5529 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5530 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5531 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5532 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5533 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5534 | |
| 5535 | HttpRequestInfo request1; |
| 5536 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5537 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5538 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5539 | request1.traffic_annotation = |
| 5540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5541 | |
| 5542 | HttpRequestInfo request2; |
| 5543 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5544 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5545 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5546 | request2.traffic_annotation = |
| 5547 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5548 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5549 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5550 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5551 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5552 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5553 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5554 | // Fetch https://www.example.org/ via HTTP. |
| 5555 | const char get1[] = |
| 5556 | "GET / HTTP/1.1\r\n" |
| 5557 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5558 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5559 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5560 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5561 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5562 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5563 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5564 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5565 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5566 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5567 | SpdySerializedFrame window_update( |
| 5568 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5569 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5570 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5571 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5572 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5573 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5574 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5575 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5576 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5577 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5578 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5579 | // Fetch https://mail.example.org/ via HTTP. |
| 5580 | const char get2[] = |
| 5581 | "GET / HTTP/1.1\r\n" |
| 5582 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5583 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5584 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5585 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5586 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5587 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5588 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5589 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5590 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5591 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5592 | |
| 5593 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5594 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5595 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5596 | }; |
| 5597 | |
| 5598 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5599 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5600 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5601 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5602 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5603 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5604 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5605 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5606 | }; |
| 5607 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5608 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5609 | arraysize(spdy_writes)); |
| 5610 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5611 | |
| 5612 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5613 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5615 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5617 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5619 | |
| 5620 | TestCompletionCallback callback; |
| 5621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5622 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5623 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5624 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5625 | |
| 5626 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5627 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5628 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5630 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5631 | ASSERT_TRUE(response); |
| 5632 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5633 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5634 | |
| 5635 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5636 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5637 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5638 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5640 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5641 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5642 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5643 | |
| 5644 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5645 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5646 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5647 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5648 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5649 | |
| 5650 | // The requests should have different IDs, since they each are using their own |
| 5651 | // separate stream. |
| 5652 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5654 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5655 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5659 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5661 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5662 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5663 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5664 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5665 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5666 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5667 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5668 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5669 | |
| 5670 | HttpRequestInfo request1; |
| 5671 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5672 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5673 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5674 | request1.traffic_annotation = |
| 5675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5676 | |
| 5677 | HttpRequestInfo request2; |
| 5678 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5679 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5680 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5681 | request2.traffic_annotation = |
| 5682 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5683 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5684 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5685 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5686 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5687 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5688 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5689 | // Fetch https://www.example.org/ via HTTP. |
| 5690 | const char get1[] = |
| 5691 | "GET / HTTP/1.1\r\n" |
| 5692 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5693 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5694 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5695 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5696 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5697 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5698 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5699 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5700 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5701 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5702 | SpdySerializedFrame window_update( |
| 5703 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5704 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5705 | // Fetch https://www.example.org/2 via HTTP. |
| 5706 | const char get2[] = |
| 5707 | "GET /2 HTTP/1.1\r\n" |
| 5708 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5709 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5710 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5711 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5712 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5713 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5714 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5715 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5716 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5717 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5718 | |
| 5719 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5720 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5721 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5722 | }; |
| 5723 | |
| 5724 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5725 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5726 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5727 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5728 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5729 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5730 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5731 | }; |
| 5732 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5733 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5734 | arraysize(spdy_writes)); |
| 5735 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5736 | |
| 5737 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5738 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5740 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5741 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5742 | |
| 5743 | TestCompletionCallback callback; |
| 5744 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5745 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5746 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5747 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5749 | |
| 5750 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5751 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5752 | |
| 5753 | LoadTimingInfo load_timing_info; |
| 5754 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5755 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5756 | |
| 5757 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5758 | ASSERT_TRUE(response); |
| 5759 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5760 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5761 | |
| 5762 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5763 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5764 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5765 | trans.reset(); |
| 5766 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5767 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5768 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5769 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5770 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5771 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5772 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5773 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5774 | |
| 5775 | LoadTimingInfo load_timing_info2; |
| 5776 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5777 | TestLoadTimingReused(load_timing_info2); |
| 5778 | |
| 5779 | // The requests should have the same ID. |
| 5780 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5781 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5782 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5783 | } |
| 5784 | |
| 5785 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5786 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5787 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5788 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5789 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5790 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5791 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5792 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5793 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5794 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5795 | |
| 5796 | HttpRequestInfo request1; |
| 5797 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5798 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5799 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5800 | request1.traffic_annotation = |
| 5801 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5802 | |
| 5803 | HttpRequestInfo request2; |
| 5804 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5805 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5806 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5807 | request2.traffic_annotation = |
| 5808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5809 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5810 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5811 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5812 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5813 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5814 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5815 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5816 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5817 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5818 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5819 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5820 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5821 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5822 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5823 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5824 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5825 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5826 | |
| 5827 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5828 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5829 | }; |
| 5830 | |
| 5831 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5832 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5833 | CreateMockRead(body1, 2, ASYNC), |
| 5834 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5835 | CreateMockRead(body2, 5, ASYNC), |
| 5836 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5837 | }; |
| 5838 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5839 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5840 | arraysize(spdy_writes)); |
| 5841 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5842 | |
| 5843 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5844 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5845 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5846 | |
| 5847 | TestCompletionCallback callback; |
| 5848 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5849 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5851 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5852 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5853 | |
| 5854 | LoadTimingInfo load_timing_info; |
| 5855 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5856 | TestLoadTimingNotReused(load_timing_info, |
| 5857 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5858 | |
| 5859 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5860 | ASSERT_TRUE(response); |
| 5861 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5862 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5863 | |
| 5864 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5865 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5866 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5867 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5868 | // Delete the first request, so the second one can reuse the socket. |
| 5869 | trans.reset(); |
| 5870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5871 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5872 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5873 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5874 | |
| 5875 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5876 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5877 | TestLoadTimingReused(load_timing_info2); |
| 5878 | |
| 5879 | // The requests should have the same ID. |
| 5880 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5882 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5883 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5884 | } |
| 5885 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5886 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5887 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5888 | HttpRequestInfo request; |
| 5889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5890 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5891 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5892 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5893 | request.traffic_annotation = |
| 5894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5895 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5896 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5897 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5898 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5899 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5900 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5902 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5903 | // Since we have proxy, should use full url |
| 5904 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5905 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5906 | "Host: www.example.org\r\n" |
| 5907 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5909 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5910 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5911 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5912 | "Host: www.example.org\r\n" |
| 5913 | "Proxy-Connection: keep-alive\r\n" |
| 5914 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5915 | }; |
| 5916 | |
| 5917 | // The proxy responds to the GET with a 407, using a persistent |
| 5918 | // connection. |
| 5919 | MockRead data_reads1[] = { |
| 5920 | // No credentials. |
| 5921 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5922 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5923 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5924 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5925 | |
| 5926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5928 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5930 | }; |
| 5931 | |
| 5932 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5933 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5935 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5938 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5942 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5944 | |
| 5945 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5946 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5947 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5948 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5949 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5950 | TestLoadTimingNotReused(load_timing_info, |
| 5951 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5954 | ASSERT_TRUE(response); |
| 5955 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5956 | EXPECT_EQ(407, response->headers->response_code()); |
| 5957 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5958 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5959 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5960 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5962 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5964 | |
| 5965 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5967 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5968 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5969 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5970 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5971 | TestLoadTimingReused(load_timing_info); |
| 5972 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5973 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5974 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5975 | |
| 5976 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5977 | EXPECT_EQ(200, response->headers->response_code()); |
| 5978 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5979 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5980 | |
| 5981 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5982 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5983 | } |
| 5984 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5985 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5986 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5987 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5988 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5989 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5990 | request.traffic_annotation = |
| 5991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5992 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5993 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5994 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5995 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5997 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5998 | // Since we have proxy, should try to establish tunnel. |
| 5999 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6000 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6001 | "Host: www.example.org:443\r\n" |
| 6002 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6003 | }; |
| 6004 | |
| 6005 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6006 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6007 | // No response body because the test stops reading here. |
| 6008 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6009 | }; |
| 6010 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6011 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6012 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6015 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6017 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6021 | |
| 6022 | rv = callback.WaitForResult(); |
| 6023 | EXPECT_EQ(expected_status, rv); |
| 6024 | } |
| 6025 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6026 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6027 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6028 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6029 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6030 | } |
| 6031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6032 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6033 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6034 | } |
| 6035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6036 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6037 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6038 | } |
| 6039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6040 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6041 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6042 | } |
| 6043 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6044 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6045 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6046 | } |
| 6047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6048 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6049 | ConnectStatusHelper( |
| 6050 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6051 | } |
| 6052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6054 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6055 | } |
| 6056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6057 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6058 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6059 | } |
| 6060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6061 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6062 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6063 | } |
| 6064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6065 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6066 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6067 | } |
| 6068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6069 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6070 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6071 | } |
| 6072 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6073 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6074 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6075 | } |
| 6076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6077 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6078 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6079 | } |
| 6080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6081 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6082 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6083 | } |
| 6084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6085 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6086 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6087 | } |
| 6088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6089 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6090 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6091 | } |
| 6092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6093 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6094 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6095 | } |
| 6096 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6097 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6098 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6099 | } |
| 6100 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6101 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6102 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6103 | } |
| 6104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6105 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6106 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6107 | } |
| 6108 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6109 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6110 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6111 | } |
| 6112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6113 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6114 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6115 | } |
| 6116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6117 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6118 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6119 | } |
| 6120 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6121 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6122 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6123 | } |
| 6124 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6125 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6126 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6127 | } |
| 6128 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6129 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6130 | ConnectStatusHelperWithExpectedStatus( |
| 6131 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6132 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6133 | } |
| 6134 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6135 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6136 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6137 | } |
| 6138 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6139 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6140 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6141 | } |
| 6142 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6143 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6144 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6145 | } |
| 6146 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6147 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6148 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6149 | } |
| 6150 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6151 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6152 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6153 | } |
| 6154 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6155 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6156 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6157 | } |
| 6158 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6159 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6160 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6161 | } |
| 6162 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6163 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6164 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6165 | } |
| 6166 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6167 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6168 | ConnectStatusHelper( |
| 6169 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6170 | } |
| 6171 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6172 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6173 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6174 | } |
| 6175 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6176 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6177 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6178 | } |
| 6179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6180 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6181 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6182 | } |
| 6183 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6184 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6185 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6186 | } |
| 6187 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6188 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6189 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6190 | } |
| 6191 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6192 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6193 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6194 | } |
| 6195 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6196 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6197 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6198 | } |
| 6199 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6200 | // Test the flow when both the proxy server AND origin server require |
| 6201 | // authentication. Again, this uses basic auth for both since that is |
| 6202 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6203 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6204 | HttpRequestInfo request; |
| 6205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6206 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6207 | request.traffic_annotation = |
| 6208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6209 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6210 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6211 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6212 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6215 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6216 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6217 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6218 | MockWrite( |
| 6219 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6220 | "Host: www.example.org\r\n" |
| 6221 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6222 | }; |
| 6223 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6224 | MockRead data_reads1[] = { |
| 6225 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6226 | // Give a couple authenticate options (only the middle one is actually |
| 6227 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6228 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6229 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6230 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6231 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6232 | // Large content-length -- won't matter, as connection will be reset. |
| 6233 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6234 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6235 | }; |
| 6236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6237 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6238 | // request we should be issuing -- the final header line contains the |
| 6239 | // proxy's credentials. |
| 6240 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6241 | MockWrite( |
| 6242 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6243 | "Host: www.example.org\r\n" |
| 6244 | "Proxy-Connection: keep-alive\r\n" |
| 6245 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6246 | }; |
| 6247 | |
| 6248 | // Now the proxy server lets the request pass through to origin server. |
| 6249 | // The origin server responds with a 401. |
| 6250 | MockRead data_reads2[] = { |
| 6251 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6252 | // Note: We are using the same realm-name as the proxy server. This is |
| 6253 | // completely valid, as realms are unique across hosts. |
| 6254 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6255 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6256 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6257 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6258 | }; |
| 6259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6260 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6261 | // the credentials for both the proxy and origin server. |
| 6262 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6263 | MockWrite( |
| 6264 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6265 | "Host: www.example.org\r\n" |
| 6266 | "Proxy-Connection: keep-alive\r\n" |
| 6267 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6268 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6269 | }; |
| 6270 | |
| 6271 | // Lastly we get the desired content. |
| 6272 | MockRead data_reads3[] = { |
| 6273 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6274 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6275 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6276 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6277 | }; |
| 6278 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6279 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6280 | data_writes1, arraysize(data_writes1)); |
| 6281 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6282 | data_writes2, arraysize(data_writes2)); |
| 6283 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6284 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6285 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6286 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6287 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6289 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6290 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6291 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6292 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6293 | |
| 6294 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6295 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6296 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6297 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6298 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6299 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6301 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6303 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6305 | |
| 6306 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6307 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6309 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6310 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6311 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6313 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6315 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6316 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6318 | |
| 6319 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6320 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6322 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6323 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6324 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6325 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6326 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6327 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6328 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6329 | // authorization headers. |
| 6330 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6331 | // The NTLM authentication unit tests are based on known test data from the |
| 6332 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6333 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6334 | // for the implementation and testing of the protocol. |
| 6335 | // |
| 6336 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6337 | |
| 6338 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6339 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6340 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6341 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6342 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6343 | request.traffic_annotation = |
| 6344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6345 | |
| 6346 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6347 | // to other auth schemes. |
| 6348 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6349 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6350 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6351 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6353 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6354 | // Generate the NTLM messages based on known test data. |
| 6355 | std::string negotiate_msg; |
| 6356 | std::string challenge_msg; |
| 6357 | std::string authenticate_msg; |
| 6358 | base::Base64Encode( |
| 6359 | base::StringPiece( |
| 6360 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6361 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6362 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6363 | base::Base64Encode( |
| 6364 | base::StringPiece( |
| 6365 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6366 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6367 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6368 | base::Base64Encode( |
| 6369 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6370 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6371 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6372 | arraysize( |
| 6373 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6374 | &authenticate_msg); |
| 6375 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6376 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6377 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6378 | "Host: server\r\n" |
| 6379 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6380 | }; |
| 6381 | |
| 6382 | MockRead data_reads1[] = { |
| 6383 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6384 | // Negotiate and NTLM are often requested together. However, we only want |
| 6385 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6386 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6387 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6388 | MockRead("Connection: close\r\n"), |
| 6389 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6390 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6391 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6392 | }; |
| 6393 | |
| 6394 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | // After restarting with a null identity, this is the |
| 6396 | // request we should be issuing -- the final header line contains a Type |
| 6397 | // 1 message. |
| 6398 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6399 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6400 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6401 | "Authorization: NTLM "), |
| 6402 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6404 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6405 | // (using correct credentials). The second request continues on the |
| 6406 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6407 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6408 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6409 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6410 | "Authorization: NTLM "), |
| 6411 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6412 | }; |
| 6413 | |
| 6414 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6415 | // The origin server responds with a Type 2 message. |
| 6416 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6417 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6418 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6419 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6420 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6421 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6422 | // Lastly we get the desired content. |
| 6423 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6424 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6425 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6426 | }; |
| 6427 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6428 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6429 | data_writes1, arraysize(data_writes1)); |
| 6430 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6431 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6432 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6433 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6434 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6435 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6437 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6440 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6443 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6444 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6446 | |
| 6447 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6448 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6449 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6450 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6451 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6452 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6453 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6454 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6456 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6457 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6458 | rv = trans.RestartWithAuth( |
| 6459 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6460 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6462 | |
| 6463 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6466 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6468 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6469 | ASSERT_TRUE(response); |
| 6470 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6472 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6474 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6476 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6477 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6480 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6481 | ASSERT_TRUE(response); |
| 6482 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6483 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6484 | |
| 6485 | std::string response_data; |
| 6486 | rv = ReadTransaction(&trans, &response_data); |
| 6487 | EXPECT_THAT(rv, IsOk()); |
| 6488 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6489 | |
| 6490 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6491 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6492 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6493 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6494 | } |
| 6495 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6496 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6497 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6498 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6499 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6500 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6501 | request.traffic_annotation = |
| 6502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6503 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6504 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6505 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6507 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6508 | // Generate the NTLM messages based on known test data. |
| 6509 | std::string negotiate_msg; |
| 6510 | std::string challenge_msg; |
| 6511 | std::string authenticate_msg; |
| 6512 | base::Base64Encode( |
| 6513 | base::StringPiece( |
| 6514 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6515 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6516 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6517 | base::Base64Encode( |
| 6518 | base::StringPiece( |
| 6519 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6520 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6521 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6522 | base::Base64Encode( |
| 6523 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6524 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6525 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6526 | arraysize( |
| 6527 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6528 | &authenticate_msg); |
| 6529 | |
| 6530 | // The authenticate message when |kWrongPassword| is sent. |
| 6531 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6532 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6533 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6534 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6535 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6536 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6537 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6538 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6539 | // Sanity check that it's the same length as the correct authenticate message |
| 6540 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6541 | ASSERT_EQ(authenticate_msg.length(), |
| 6542 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6543 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6544 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6545 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6546 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6547 | "Host: server\r\n" |
| 6548 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6549 | }; |
| 6550 | |
| 6551 | MockRead data_reads1[] = { |
| 6552 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6553 | // Negotiate and NTLM are often requested together. However, we only want |
| 6554 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6555 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6556 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6557 | MockRead("Connection: close\r\n"), |
| 6558 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6559 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6560 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6561 | }; |
| 6562 | |
| 6563 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6564 | // After restarting with a null identity, this is the |
| 6565 | // request we should be issuing -- the final header line contains a Type |
| 6566 | // 1 message. |
| 6567 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6568 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6569 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6570 | "Authorization: NTLM "), |
| 6571 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6573 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6574 | // (using incorrect credentials). The second request continues on the |
| 6575 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6576 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6577 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6578 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6579 | "Authorization: NTLM "), |
| 6580 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6581 | }; |
| 6582 | |
| 6583 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6584 | // The origin server responds with a Type 2 message. |
| 6585 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6586 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6587 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6588 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6589 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6590 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6591 | // Wrong password. |
| 6592 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6593 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6594 | MockRead("Content-Length: 42\r\n"), |
| 6595 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6596 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6597 | }; |
| 6598 | |
| 6599 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6600 | // After restarting with a null identity, this is the |
| 6601 | // request we should be issuing -- the final header line contains a Type |
| 6602 | // 1 message. |
| 6603 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6604 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6605 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6606 | "Authorization: NTLM "), |
| 6607 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6609 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6610 | // (the credentials for the origin server). The second request continues |
| 6611 | // on the same connection. |
| 6612 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6613 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6614 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6615 | "Authorization: NTLM "), |
| 6616 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6617 | }; |
| 6618 | |
| 6619 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6620 | // The origin server responds with a Type 2 message. |
| 6621 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6622 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6623 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6624 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6625 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6626 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6627 | // Lastly we get the desired content. |
| 6628 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6629 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6630 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6631 | }; |
| 6632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6633 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6634 | data_writes1, arraysize(data_writes1)); |
| 6635 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6636 | data_writes2, arraysize(data_writes2)); |
| 6637 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6638 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6639 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6640 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6641 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6642 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6643 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6644 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6645 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6647 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6650 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6654 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6656 | |
| 6657 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6658 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6660 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6662 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6663 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6664 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6666 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6667 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6668 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6669 | rv = trans.RestartWithAuth( |
| 6670 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6671 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6673 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6674 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6675 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6677 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6678 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6679 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6681 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6682 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6683 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6685 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6686 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6687 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6689 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6690 | |
| 6691 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6692 | rv = trans.RestartWithAuth( |
| 6693 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6694 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6696 | |
| 6697 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6698 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6700 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6701 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6702 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6703 | |
| 6704 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6705 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6707 | |
| 6708 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6709 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6711 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6712 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6713 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6714 | |
| 6715 | std::string response_data; |
| 6716 | rv = ReadTransaction(&trans, &response_data); |
| 6717 | EXPECT_THAT(rv, IsOk()); |
| 6718 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6719 | |
| 6720 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6721 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6722 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6723 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6724 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6725 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6726 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6727 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6728 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6729 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6730 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6731 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6732 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6733 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6734 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6735 | |
| 6736 | HttpRequestInfo request; |
| 6737 | request.method = "GET"; |
| 6738 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6739 | request.traffic_annotation = |
| 6740 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6741 | |
| 6742 | // First request without credentials. |
| 6743 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6744 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6745 | 1, std::move(request_headers0), LOWEST, true)); |
| 6746 | |
| 6747 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6748 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6749 | response_headers0["www-authenticate"] = "NTLM"; |
| 6750 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6751 | 1, std::move(response_headers0), true)); |
| 6752 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6753 | // Stream 1 is closed. |
| 6754 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6755 | |
| 6756 | // Generate the NTLM messages based on known test data. |
| 6757 | std::string negotiate_msg; |
| 6758 | std::string challenge_msg; |
| 6759 | std::string authenticate_msg; |
| 6760 | base::Base64Encode( |
| 6761 | base::StringPiece( |
| 6762 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6763 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6764 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6765 | base::Base64Encode( |
| 6766 | base::StringPiece( |
| 6767 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6768 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6769 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6770 | base::Base64Encode( |
| 6771 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6772 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6773 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6774 | arraysize( |
| 6775 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6776 | &authenticate_msg); |
| 6777 | |
| 6778 | // Retry with authorization header. |
| 6779 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6780 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6781 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6782 | 3, std::move(request_headers1), LOWEST, true)); |
| 6783 | |
| 6784 | SpdySerializedFrame rst( |
| 6785 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6786 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6787 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6788 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6789 | |
| 6790 | // Retry yet again using HTTP/1.1. |
| 6791 | MockWrite writes1[] = { |
| 6792 | // After restarting with a null identity, this is the |
| 6793 | // request we should be issuing -- the final header line contains a Type |
| 6794 | // 1 message. |
| 6795 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6796 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6797 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6798 | "Authorization: NTLM "), |
| 6799 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6800 | |
| 6801 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6802 | // (the credentials for the origin server). The second request continues |
| 6803 | // on the same connection. |
| 6804 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6805 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6806 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6807 | "Authorization: NTLM "), |
| 6808 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6809 | }; |
| 6810 | |
| 6811 | MockRead reads1[] = { |
| 6812 | // The origin server responds with a Type 2 message. |
| 6813 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6814 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6815 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6816 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6817 | MockRead("You are not authorized to view this page\r\n"), |
| 6818 | |
| 6819 | // Lastly we get the desired content. |
| 6820 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6821 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6822 | 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] | 6823 | }; |
| 6824 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6825 | arraysize(writes0)); |
| 6826 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6827 | arraysize(writes1)); |
| 6828 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6829 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6830 | |
| 6831 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6832 | ssl0.next_proto = kProtoHTTP2; |
| 6833 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6834 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6835 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6836 | |
| 6837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6838 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6839 | |
| 6840 | TestCompletionCallback callback1; |
| 6841 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6843 | |
| 6844 | rv = callback1.WaitForResult(); |
| 6845 | EXPECT_THAT(rv, IsOk()); |
| 6846 | |
| 6847 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6848 | |
| 6849 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6850 | ASSERT_TRUE(response); |
| 6851 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6852 | |
| 6853 | TestCompletionCallback callback2; |
| 6854 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6855 | rv = trans.RestartWithAuth( |
| 6856 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6857 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6859 | |
| 6860 | rv = callback2.WaitForResult(); |
| 6861 | EXPECT_THAT(rv, IsOk()); |
| 6862 | |
| 6863 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6864 | |
| 6865 | response = trans.GetResponseInfo(); |
| 6866 | ASSERT_TRUE(response); |
| 6867 | EXPECT_FALSE(response->auth_challenge); |
| 6868 | |
| 6869 | TestCompletionCallback callback3; |
| 6870 | |
| 6871 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6872 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6873 | |
| 6874 | rv = callback3.WaitForResult(); |
| 6875 | EXPECT_THAT(rv, IsOk()); |
| 6876 | |
| 6877 | response = trans.GetResponseInfo(); |
| 6878 | ASSERT_TRUE(response); |
| 6879 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6880 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6881 | |
| 6882 | std::string response_data; |
| 6883 | rv = ReadTransaction(&trans, &response_data); |
| 6884 | EXPECT_THAT(rv, IsOk()); |
| 6885 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6886 | |
| 6887 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6888 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6889 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6890 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6891 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame^] | 6892 | |
| 6893 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 6894 | // do no retry forever checking for TLS version interference. This is a |
| 6895 | // regression test for https://crbug.com/823387. |
| 6896 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 6897 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 6898 | // https://origin/. |
| 6899 | session_deps_.proxy_resolution_service = |
| 6900 | ProxyResolutionService::CreateFixedFromPacResult( |
| 6901 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6902 | |
| 6903 | SSLConfig config; |
| 6904 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 6905 | session_deps_.ssl_config_service = |
| 6906 | base::MakeRefCounted<TestSSLConfigService>(config); |
| 6907 | |
| 6908 | HttpRequestInfo request; |
| 6909 | request.method = "GET"; |
| 6910 | request.url = GURL("https://origin/"); |
| 6911 | request.traffic_annotation = |
| 6912 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6913 | |
| 6914 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6915 | // to other auth schemes. |
| 6916 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6917 | |
| 6918 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6919 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 6920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6921 | |
| 6922 | // Generate the NTLM messages based on known test data. |
| 6923 | std::string negotiate_msg; |
| 6924 | std::string challenge_msg; |
| 6925 | std::string authenticate_msg; |
| 6926 | base::Base64Encode( |
| 6927 | base::StringPiece( |
| 6928 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6929 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6930 | &negotiate_msg); |
| 6931 | base::Base64Encode( |
| 6932 | base::StringPiece( |
| 6933 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6934 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6935 | &challenge_msg); |
| 6936 | base::Base64Encode( |
| 6937 | base::StringPiece( |
| 6938 | reinterpret_cast<const char*>( |
| 6939 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6940 | arraysize( |
| 6941 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 6942 | &authenticate_msg); |
| 6943 | |
| 6944 | MockWrite data_writes[] = { |
| 6945 | // The initial CONNECT request. |
| 6946 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6947 | "Host: origin:443\r\n" |
| 6948 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6949 | |
| 6950 | // After restarting with an identity. |
| 6951 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6952 | "Host: origin:443\r\n" |
| 6953 | "Proxy-Connection: keep-alive\r\n" |
| 6954 | "Proxy-Authorization: NTLM "), |
| 6955 | MockWrite(negotiate_msg.c_str()), |
| 6956 | // End headers. |
| 6957 | MockWrite("\r\n\r\n"), |
| 6958 | |
| 6959 | // The second restart. |
| 6960 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6961 | "Host: origin:443\r\n" |
| 6962 | "Proxy-Connection: keep-alive\r\n" |
| 6963 | "Proxy-Authorization: NTLM "), |
| 6964 | MockWrite(authenticate_msg.c_str()), |
| 6965 | // End headers. |
| 6966 | MockWrite("\r\n\r\n"), |
| 6967 | }; |
| 6968 | |
| 6969 | MockRead data_reads[] = { |
| 6970 | // The initial NTLM response. |
| 6971 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6972 | "Content-Length: 0\r\n" |
| 6973 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 6974 | |
| 6975 | // The NTLM challenge message. |
| 6976 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6977 | "Content-Length: 0\r\n" |
| 6978 | "Proxy-Authenticate: NTLM "), |
| 6979 | MockRead(challenge_msg.c_str()), |
| 6980 | // End headers. |
| 6981 | MockRead("\r\n\r\n"), |
| 6982 | |
| 6983 | // Finally the tunnel is established. |
| 6984 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 6985 | }; |
| 6986 | |
| 6987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6988 | arraysize(data_writes)); |
| 6989 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
| 6990 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), data_writes, |
| 6991 | arraysize(data_writes)); |
| 6992 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
| 6993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 6995 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 6997 | |
| 6998 | // Start the transaction. The proxy responds with an NTLM authentication |
| 6999 | // request. |
| 7000 | TestCompletionCallback callback; |
| 7001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7002 | int rv = callback.GetResult( |
| 7003 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7004 | |
| 7005 | EXPECT_THAT(rv, IsOk()); |
| 7006 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7008 | ASSERT_TRUE(response); |
| 7009 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7010 | |
| 7011 | // Configure credentials. The proxy responds with the challenge message. |
| 7012 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7013 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7014 | callback.callback())); |
| 7015 | EXPECT_THAT(rv, IsOk()); |
| 7016 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7017 | response = trans.GetResponseInfo(); |
| 7018 | ASSERT_TRUE(response); |
| 7019 | EXPECT_FALSE(response->auth_challenge); |
| 7020 | |
| 7021 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7022 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7023 | // restart the process. The proxy responds with another NTLM authentiation |
| 7024 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7025 | rv = callback.GetResult( |
| 7026 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7027 | EXPECT_THAT(rv, IsOk()); |
| 7028 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7029 | response = trans.GetResponseInfo(); |
| 7030 | ASSERT_TRUE(response); |
| 7031 | EXPECT_FALSE(response->auth_challenge); |
| 7032 | |
| 7033 | // The proxy responds with the NTLM challenge message. |
| 7034 | rv = callback.GetResult( |
| 7035 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7036 | EXPECT_THAT(rv, IsOk()); |
| 7037 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7038 | response = trans.GetResponseInfo(); |
| 7039 | ASSERT_TRUE(response); |
| 7040 | EXPECT_FALSE(response->auth_challenge); |
| 7041 | |
| 7042 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7043 | // handshake resets again. We should not retry again. |
| 7044 | rv = callback.GetResult( |
| 7045 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7046 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7047 | } |
| 7048 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7049 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7050 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7051 | // Test reading a server response which has only headers, and no body. |
| 7052 | // After some maximum number of bytes is consumed, the transaction should |
| 7053 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7054 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7055 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7056 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7057 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7058 | request.traffic_annotation = |
| 7059 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7063 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7064 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7065 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7066 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7067 | |
| 7068 | MockRead data_reads[] = { |
| 7069 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7070 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7071 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7072 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7073 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7074 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7077 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7079 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7081 | |
| 7082 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7083 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7084 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7085 | |
| 7086 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7087 | // establish tunnel. |
| 7088 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7089 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7090 | HttpRequestInfo request; |
| 7091 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7092 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7093 | request.traffic_annotation = |
| 7094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7095 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7096 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7097 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7098 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7101 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7102 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7103 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7104 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7105 | // Since we have proxy, should try to establish tunnel. |
| 7106 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7107 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7108 | "Host: www.example.org:443\r\n" |
| 7109 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7110 | }; |
| 7111 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7112 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7113 | // connection. Usually a proxy would return 501 (not implemented), |
| 7114 | // or 200 (tunnel established). |
| 7115 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7116 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7117 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7118 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7119 | }; |
| 7120 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7121 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7122 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7125 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7127 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7129 | |
| 7130 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7131 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7132 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7133 | // Empty the current queue. This is necessary because idle sockets are |
| 7134 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7135 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7136 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7137 | // We now check to make sure the TCPClientSocket was not added back to |
| 7138 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7139 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7140 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7141 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7142 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7143 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7144 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7145 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7146 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7147 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7148 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7150 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7151 | request.traffic_annotation = |
| 7152 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7153 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7155 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7157 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7158 | MockRead data_reads[] = { |
| 7159 | // A part of the response body is received with the response headers. |
| 7160 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7161 | // The rest of the response body is received in two parts. |
| 7162 | MockRead("lo"), |
| 7163 | MockRead(" world"), |
| 7164 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7165 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7166 | }; |
| 7167 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7168 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7169 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7171 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7172 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7173 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7175 | |
| 7176 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7177 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7180 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7181 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7182 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7183 | std::string status_line = response->headers->GetStatusLine(); |
| 7184 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7185 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7186 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7187 | |
| 7188 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7189 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7191 | EXPECT_EQ("hello world", response_data); |
| 7192 | |
| 7193 | // Empty the current queue. This is necessary because idle sockets are |
| 7194 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7195 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7196 | |
| 7197 | // 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] | 7198 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7199 | } |
| 7200 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7201 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7202 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7203 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7204 | HttpRequestInfo request; |
| 7205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7206 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7207 | request.traffic_annotation = |
| 7208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7209 | |
| 7210 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7211 | MockWrite( |
| 7212 | "GET / HTTP/1.1\r\n" |
| 7213 | "Host: www.example.org\r\n" |
| 7214 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7215 | }; |
| 7216 | |
| 7217 | MockRead data_reads[] = { |
| 7218 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7219 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7220 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7221 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7222 | }; |
| 7223 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7224 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7226 | |
| 7227 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7228 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7231 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7232 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7235 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7236 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7237 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7239 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7241 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7242 | ASSERT_TRUE(response); |
| 7243 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7244 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7245 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7246 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7247 | |
| 7248 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7249 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7251 | EXPECT_EQ("hello world", response_data); |
| 7252 | |
| 7253 | // Empty the current queue. This is necessary because idle sockets are |
| 7254 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7255 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7256 | |
| 7257 | // 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] | 7258 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7259 | } |
| 7260 | |
| 7261 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7262 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7263 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7264 | HttpRequestInfo request; |
| 7265 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7266 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7267 | request.traffic_annotation = |
| 7268 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7269 | |
| 7270 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7271 | MockWrite( |
| 7272 | "GET / HTTP/1.1\r\n" |
| 7273 | "Host: www.example.org\r\n" |
| 7274 | "Connection: keep-alive\r\n\r\n"), |
| 7275 | MockWrite( |
| 7276 | "GET / HTTP/1.1\r\n" |
| 7277 | "Host: www.example.org\r\n" |
| 7278 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7279 | }; |
| 7280 | |
| 7281 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7282 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7283 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7284 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7285 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7286 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7287 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7289 | |
| 7290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7291 | data_writes, arraysize(data_writes)); |
| 7292 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 7293 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7294 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7295 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7297 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7298 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7300 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7301 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7302 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7303 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7304 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7306 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7307 | |
| 7308 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7309 | ASSERT_TRUE(response); |
| 7310 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7311 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7312 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7313 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7314 | |
| 7315 | std::string response_data; |
| 7316 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7318 | EXPECT_EQ("hello world", response_data); |
| 7319 | |
| 7320 | // Empty the current queue. This is necessary because idle sockets are |
| 7321 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7322 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7323 | |
| 7324 | // 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] | 7325 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7326 | |
| 7327 | // Now start the second transaction, which should reuse the previous socket. |
| 7328 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7329 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7330 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7332 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7333 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7335 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7336 | |
| 7337 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7338 | ASSERT_TRUE(response); |
| 7339 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7340 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7341 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7342 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7343 | |
| 7344 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7345 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7346 | EXPECT_EQ("hello world", response_data); |
| 7347 | |
| 7348 | // Empty the current queue. This is necessary because idle sockets are |
| 7349 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7350 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7351 | |
| 7352 | // 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] | 7353 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7354 | } |
| 7355 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7356 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7357 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7358 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7359 | HttpRequestInfo request; |
| 7360 | request.method = "GET"; |
| 7361 | request.url = GURL("http://www.example.org/"); |
| 7362 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7363 | request.traffic_annotation = |
| 7364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7365 | |
| 7366 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7368 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7369 | |
| 7370 | MockRead data_reads[] = { |
| 7371 | // A part of the response body is received with the response headers. |
| 7372 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7373 | // The rest of the response body is received in two parts. |
| 7374 | MockRead("lo"), MockRead(" world"), |
| 7375 | MockRead("junk"), // Should not be read!! |
| 7376 | MockRead(SYNCHRONOUS, OK), |
| 7377 | }; |
| 7378 | |
| 7379 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7380 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7381 | |
| 7382 | TestCompletionCallback callback; |
| 7383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7386 | |
| 7387 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7390 | ASSERT_TRUE(response); |
| 7391 | EXPECT_TRUE(response->headers); |
| 7392 | std::string status_line = response->headers->GetStatusLine(); |
| 7393 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7394 | |
| 7395 | // Make memory critical notification and ensure the transaction still has been |
| 7396 | // operating right. |
| 7397 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7398 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7399 | base::RunLoop().RunUntilIdle(); |
| 7400 | |
| 7401 | // Socket should not be flushed as long as it is not idle. |
| 7402 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7403 | |
| 7404 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7405 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7406 | EXPECT_THAT(rv, IsOk()); |
| 7407 | EXPECT_EQ("hello world", response_data); |
| 7408 | |
| 7409 | // Empty the current queue. This is necessary because idle sockets are |
| 7410 | // added to the connection pool asynchronously with a PostTask. |
| 7411 | base::RunLoop().RunUntilIdle(); |
| 7412 | |
| 7413 | // We now check to make sure the socket was added back to the pool. |
| 7414 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7415 | |
| 7416 | // Idle sockets should be flushed now. |
| 7417 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7418 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7419 | base::RunLoop().RunUntilIdle(); |
| 7420 | |
| 7421 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7422 | } |
| 7423 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7424 | // Disable idle socket closing on memory pressure. |
| 7425 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7426 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7427 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7428 | HttpRequestInfo request; |
| 7429 | request.method = "GET"; |
| 7430 | request.url = GURL("http://www.example.org/"); |
| 7431 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7432 | request.traffic_annotation = |
| 7433 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7434 | |
| 7435 | // Disable idle socket closing on memory pressure. |
| 7436 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7438 | |
| 7439 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7440 | |
| 7441 | MockRead data_reads[] = { |
| 7442 | // A part of the response body is received with the response headers. |
| 7443 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7444 | // The rest of the response body is received in two parts. |
| 7445 | MockRead("lo"), MockRead(" world"), |
| 7446 | MockRead("junk"), // Should not be read!! |
| 7447 | MockRead(SYNCHRONOUS, OK), |
| 7448 | }; |
| 7449 | |
| 7450 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7452 | |
| 7453 | TestCompletionCallback callback; |
| 7454 | |
| 7455 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7457 | |
| 7458 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7459 | |
| 7460 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7461 | ASSERT_TRUE(response); |
| 7462 | EXPECT_TRUE(response->headers); |
| 7463 | std::string status_line = response->headers->GetStatusLine(); |
| 7464 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7465 | |
| 7466 | // Make memory critical notification and ensure the transaction still has been |
| 7467 | // operating right. |
| 7468 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7469 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7470 | base::RunLoop().RunUntilIdle(); |
| 7471 | |
| 7472 | // Socket should not be flushed as long as it is not idle. |
| 7473 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7474 | |
| 7475 | std::string response_data; |
| 7476 | rv = ReadTransaction(&trans, &response_data); |
| 7477 | EXPECT_THAT(rv, IsOk()); |
| 7478 | EXPECT_EQ("hello world", response_data); |
| 7479 | |
| 7480 | // Empty the current queue. This is necessary because idle sockets are |
| 7481 | // added to the connection pool asynchronously with a PostTask. |
| 7482 | base::RunLoop().RunUntilIdle(); |
| 7483 | |
| 7484 | // We now check to make sure the socket was added back to the pool. |
| 7485 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7486 | |
| 7487 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7488 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7489 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7490 | base::RunLoop().RunUntilIdle(); |
| 7491 | |
| 7492 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7493 | |
| 7494 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7495 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7496 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7497 | base::RunLoop().RunUntilIdle(); |
| 7498 | |
| 7499 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7500 | } |
| 7501 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7502 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7503 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7504 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7505 | HttpRequestInfo request; |
| 7506 | request.method = "GET"; |
| 7507 | request.url = GURL("https://www.example.org/"); |
| 7508 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7509 | request.traffic_annotation = |
| 7510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7511 | |
| 7512 | MockWrite data_writes[] = { |
| 7513 | MockWrite("GET / HTTP/1.1\r\n" |
| 7514 | "Host: www.example.org\r\n" |
| 7515 | "Connection: keep-alive\r\n\r\n"), |
| 7516 | }; |
| 7517 | |
| 7518 | MockRead data_reads[] = { |
| 7519 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7520 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7521 | |
| 7522 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7524 | |
| 7525 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7526 | arraysize(data_writes)); |
| 7527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7528 | |
| 7529 | TestCompletionCallback callback; |
| 7530 | |
| 7531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7533 | |
| 7534 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7535 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7536 | |
| 7537 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7539 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7540 | ASSERT_TRUE(response); |
| 7541 | ASSERT_TRUE(response->headers); |
| 7542 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7543 | |
| 7544 | // Make memory critical notification and ensure the transaction still has been |
| 7545 | // operating right. |
| 7546 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7547 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7548 | base::RunLoop().RunUntilIdle(); |
| 7549 | |
| 7550 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7551 | |
| 7552 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7553 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7554 | EXPECT_THAT(rv, IsOk()); |
| 7555 | EXPECT_EQ("hello world", response_data); |
| 7556 | |
| 7557 | // Empty the current queue. This is necessary because idle sockets are |
| 7558 | // added to the connection pool asynchronously with a PostTask. |
| 7559 | base::RunLoop().RunUntilIdle(); |
| 7560 | |
| 7561 | // We now check to make sure the socket was added back to the pool. |
| 7562 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7563 | |
| 7564 | // Make memory notification once again and ensure idle socket is closed. |
| 7565 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7566 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7567 | base::RunLoop().RunUntilIdle(); |
| 7568 | |
| 7569 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7570 | } |
| 7571 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7572 | // Make sure that we recycle a socket after a zero-length response. |
| 7573 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7574 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7575 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7577 | request.url = GURL( |
| 7578 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7579 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7580 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7581 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7582 | request.traffic_annotation = |
| 7583 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7584 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7586 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7587 | MockRead data_reads[] = { |
| 7588 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7589 | "Content-Length: 0\r\n" |
| 7590 | "Content-Type: text/html\r\n\r\n"), |
| 7591 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7592 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7593 | }; |
| 7594 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7595 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7597 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7598 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7599 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7601 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7602 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7606 | |
| 7607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7608 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7610 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7611 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7612 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7613 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7614 | std::string status_line = response->headers->GetStatusLine(); |
| 7615 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7616 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7617 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7618 | |
| 7619 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7620 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7622 | EXPECT_EQ("", response_data); |
| 7623 | |
| 7624 | // Empty the current queue. This is necessary because idle sockets are |
| 7625 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7626 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7627 | |
| 7628 | // 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] | 7629 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7630 | } |
| 7631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7632 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7633 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7634 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7635 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7636 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7637 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7638 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7639 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7640 | // after use. |
| 7641 | request[0].method = "GET"; |
| 7642 | request[0].url = GURL("http://www.google.com/"); |
| 7643 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7644 | request[0].traffic_annotation = |
| 7645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7646 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7647 | // transaction 1. The first attempts fails when writing the POST data. |
| 7648 | // This causes the transaction to retry with a new socket. The second |
| 7649 | // attempt succeeds. |
| 7650 | request[1].method = "POST"; |
| 7651 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7652 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7653 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7654 | request[1].traffic_annotation = |
| 7655 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7656 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7657 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7658 | |
| 7659 | // The first socket is used for transaction 1 and the first attempt of |
| 7660 | // transaction 2. |
| 7661 | |
| 7662 | // The response of transaction 1. |
| 7663 | MockRead data_reads1[] = { |
| 7664 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7665 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7666 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7667 | }; |
| 7668 | // The mock write results of transaction 1 and the first attempt of |
| 7669 | // transaction 2. |
| 7670 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7671 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7672 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7673 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7674 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7675 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7676 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7677 | |
| 7678 | // The second socket is used for the second attempt of transaction 2. |
| 7679 | |
| 7680 | // The response of transaction 2. |
| 7681 | MockRead data_reads2[] = { |
| 7682 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7683 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7685 | }; |
| 7686 | // The mock write results of the second attempt of transaction 2. |
| 7687 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7688 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7689 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7690 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7691 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7692 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7693 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7694 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7695 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7696 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7697 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7698 | "hello world", "welcome" |
| 7699 | }; |
| 7700 | |
| 7701 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7702 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7704 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7706 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7708 | |
| 7709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7712 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7713 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7714 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7715 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7716 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7717 | |
| 7718 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7719 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7721 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7722 | } |
| 7723 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7724 | |
| 7725 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7726 | // 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] | 7727 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7728 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7729 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7730 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7731 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7732 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7733 | request.traffic_annotation = |
| 7734 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7738 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7739 | // The password contains an escaped character -- for this test to pass it |
| 7740 | // will need to be unescaped by HttpNetworkTransaction. |
| 7741 | EXPECT_EQ("b%40r", request.url.password()); |
| 7742 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7743 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7744 | MockWrite( |
| 7745 | "GET / HTTP/1.1\r\n" |
| 7746 | "Host: www.example.org\r\n" |
| 7747 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7748 | }; |
| 7749 | |
| 7750 | MockRead data_reads1[] = { |
| 7751 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7752 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7753 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7754 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7755 | }; |
| 7756 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7757 | // After the challenge above, the transaction will be restarted using the |
| 7758 | // identity from the url (foo, b@r) to answer the challenge. |
| 7759 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7760 | MockWrite( |
| 7761 | "GET / HTTP/1.1\r\n" |
| 7762 | "Host: www.example.org\r\n" |
| 7763 | "Connection: keep-alive\r\n" |
| 7764 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7765 | }; |
| 7766 | |
| 7767 | MockRead data_reads2[] = { |
| 7768 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7769 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7770 | MockRead(SYNCHRONOUS, OK), |
| 7771 | }; |
| 7772 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7773 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7774 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7775 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7776 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7777 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7778 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7780 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7781 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7783 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7784 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7785 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7786 | |
| 7787 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7788 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7790 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7791 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7792 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7794 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7795 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7796 | |
| 7797 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7798 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7799 | |
| 7800 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7801 | |
| 7802 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7803 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7804 | } |
| 7805 | |
| 7806 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7807 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7808 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7809 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7810 | HttpRequestInfo request; |
| 7811 | request.method = "GET"; |
| 7812 | // Note: the URL has a username:password in it. The password "baz" is |
| 7813 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7814 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7815 | |
| 7816 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7817 | request.traffic_annotation = |
| 7818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7819 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7822 | |
| 7823 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7824 | MockWrite( |
| 7825 | "GET / HTTP/1.1\r\n" |
| 7826 | "Host: www.example.org\r\n" |
| 7827 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7828 | }; |
| 7829 | |
| 7830 | MockRead data_reads1[] = { |
| 7831 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7832 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7833 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7834 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7835 | }; |
| 7836 | |
| 7837 | // After the challenge above, the transaction will be restarted using the |
| 7838 | // identity from the url (foo, baz) to answer the challenge. |
| 7839 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7840 | MockWrite( |
| 7841 | "GET / HTTP/1.1\r\n" |
| 7842 | "Host: www.example.org\r\n" |
| 7843 | "Connection: keep-alive\r\n" |
| 7844 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7845 | }; |
| 7846 | |
| 7847 | MockRead data_reads2[] = { |
| 7848 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7849 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7850 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7851 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7852 | }; |
| 7853 | |
| 7854 | // After the challenge above, the transaction will be restarted using the |
| 7855 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7856 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7857 | MockWrite( |
| 7858 | "GET / HTTP/1.1\r\n" |
| 7859 | "Host: www.example.org\r\n" |
| 7860 | "Connection: keep-alive\r\n" |
| 7861 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7862 | }; |
| 7863 | |
| 7864 | MockRead data_reads3[] = { |
| 7865 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7866 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7867 | MockRead(SYNCHRONOUS, OK), |
| 7868 | }; |
| 7869 | |
| 7870 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7871 | data_writes1, arraysize(data_writes1)); |
| 7872 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7873 | data_writes2, arraysize(data_writes2)); |
| 7874 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7875 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7877 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7878 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7879 | |
| 7880 | TestCompletionCallback callback1; |
| 7881 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7882 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7884 | |
| 7885 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7888 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7889 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7890 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7892 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7893 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7894 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7897 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7898 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7899 | |
| 7900 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7901 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7903 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7904 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7905 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7907 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7908 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7909 | |
| 7910 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7911 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7912 | |
| 7913 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7914 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7915 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7916 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7917 | } |
| 7918 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7919 | |
| 7920 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7921 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7922 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7923 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7924 | HttpRequestInfo request; |
| 7925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7926 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7927 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7928 | request.traffic_annotation = |
| 7929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7933 | |
| 7934 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7935 | MockWrite( |
| 7936 | "GET / HTTP/1.1\r\n" |
| 7937 | "Host: www.example.org\r\n" |
| 7938 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7939 | }; |
| 7940 | |
| 7941 | MockRead data_reads1[] = { |
| 7942 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7943 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7944 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7945 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7946 | }; |
| 7947 | |
| 7948 | // After the challenge above, the transaction will be restarted using the |
| 7949 | // identity supplied by the user, not the one in the URL, to answer the |
| 7950 | // challenge. |
| 7951 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7952 | MockWrite( |
| 7953 | "GET / HTTP/1.1\r\n" |
| 7954 | "Host: www.example.org\r\n" |
| 7955 | "Connection: keep-alive\r\n" |
| 7956 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7957 | }; |
| 7958 | |
| 7959 | MockRead data_reads3[] = { |
| 7960 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7961 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7962 | MockRead(SYNCHRONOUS, OK), |
| 7963 | }; |
| 7964 | |
| 7965 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7966 | data_writes1, arraysize(data_writes1)); |
| 7967 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7968 | data_writes3, arraysize(data_writes3)); |
| 7969 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7970 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7971 | |
| 7972 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7973 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7975 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7976 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7977 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7979 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7980 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7981 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7982 | |
| 7983 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7984 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7986 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7987 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7988 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7990 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7991 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7992 | |
| 7993 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7994 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7995 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7996 | |
| 7997 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7998 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7999 | } |
| 8000 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8001 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8002 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8004 | |
| 8005 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8006 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8007 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8009 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8010 | request.traffic_annotation = |
| 8011 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8013 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8014 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8015 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8016 | MockWrite( |
| 8017 | "GET /x/y/z HTTP/1.1\r\n" |
| 8018 | "Host: www.example.org\r\n" |
| 8019 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8020 | }; |
| 8021 | |
| 8022 | MockRead data_reads1[] = { |
| 8023 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8024 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8025 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8026 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8027 | }; |
| 8028 | |
| 8029 | // Resend with authorization (username=foo, password=bar) |
| 8030 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8031 | MockWrite( |
| 8032 | "GET /x/y/z HTTP/1.1\r\n" |
| 8033 | "Host: www.example.org\r\n" |
| 8034 | "Connection: keep-alive\r\n" |
| 8035 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8036 | }; |
| 8037 | |
| 8038 | // Sever accepts the authorization. |
| 8039 | MockRead data_reads2[] = { |
| 8040 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8041 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8042 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8043 | }; |
| 8044 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8045 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8046 | data_writes1, arraysize(data_writes1)); |
| 8047 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8048 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8049 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8050 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[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 callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8054 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8056 | |
| 8057 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8058 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8060 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8061 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8062 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8064 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8066 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8067 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8069 | |
| 8070 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8071 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8073 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8074 | ASSERT_TRUE(response); |
| 8075 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8076 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8077 | } |
| 8078 | |
| 8079 | // ------------------------------------------------------------------------ |
| 8080 | |
| 8081 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8082 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8083 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8084 | request.method = "GET"; |
| 8085 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8086 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8087 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8088 | request.traffic_annotation = |
| 8089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8092 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8093 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8094 | MockWrite( |
| 8095 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8096 | "Host: www.example.org\r\n" |
| 8097 | "Connection: keep-alive\r\n" |
| 8098 | // Send preemptive authorization for MyRealm1 |
| 8099 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8100 | }; |
| 8101 | |
| 8102 | // The server didn't like the preemptive authorization, and |
| 8103 | // challenges us for a different realm (MyRealm2). |
| 8104 | MockRead data_reads1[] = { |
| 8105 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8106 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8107 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8108 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8109 | }; |
| 8110 | |
| 8111 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8112 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8113 | MockWrite( |
| 8114 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8115 | "Host: www.example.org\r\n" |
| 8116 | "Connection: keep-alive\r\n" |
| 8117 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8118 | }; |
| 8119 | |
| 8120 | // Sever accepts the authorization. |
| 8121 | MockRead data_reads2[] = { |
| 8122 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8123 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8124 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8125 | }; |
| 8126 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8127 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8128 | data_writes1, arraysize(data_writes1)); |
| 8129 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8130 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8131 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8132 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8134 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8135 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8136 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8138 | |
| 8139 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8140 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8142 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8143 | ASSERT_TRUE(response); |
| 8144 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8145 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8146 | EXPECT_EQ("http://www.example.org", |
| 8147 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8148 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8149 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8150 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8151 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8153 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8154 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8156 | |
| 8157 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8158 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8159 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8160 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8161 | ASSERT_TRUE(response); |
| 8162 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8163 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8164 | } |
| 8165 | |
| 8166 | // ------------------------------------------------------------------------ |
| 8167 | |
| 8168 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8169 | // succeed with preemptive authorization. |
| 8170 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8171 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8172 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8173 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8174 | request.traffic_annotation = |
| 8175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8178 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8179 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8180 | MockWrite( |
| 8181 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8182 | "Host: www.example.org\r\n" |
| 8183 | "Connection: keep-alive\r\n" |
| 8184 | // The authorization for MyRealm1 gets sent preemptively |
| 8185 | // (since the url is in the same protection space) |
| 8186 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8187 | }; |
| 8188 | |
| 8189 | // Sever accepts the preemptive authorization |
| 8190 | MockRead data_reads1[] = { |
| 8191 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8192 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8193 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8194 | }; |
| 8195 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8196 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8197 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8200 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8202 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8204 | |
| 8205 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8206 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8208 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8209 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8210 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8211 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8212 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8213 | } |
| 8214 | |
| 8215 | // ------------------------------------------------------------------------ |
| 8216 | |
| 8217 | // Transaction 4: request another URL in MyRealm (however the |
| 8218 | // url is not known to belong to the protection space, so no pre-auth). |
| 8219 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8220 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8221 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8222 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8223 | request.traffic_annotation = |
| 8224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8227 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8228 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8229 | MockWrite( |
| 8230 | "GET /x/1 HTTP/1.1\r\n" |
| 8231 | "Host: www.example.org\r\n" |
| 8232 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8233 | }; |
| 8234 | |
| 8235 | MockRead data_reads1[] = { |
| 8236 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8237 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8238 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8239 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8240 | }; |
| 8241 | |
| 8242 | // Resend with authorization from MyRealm's cache. |
| 8243 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8244 | MockWrite( |
| 8245 | "GET /x/1 HTTP/1.1\r\n" |
| 8246 | "Host: www.example.org\r\n" |
| 8247 | "Connection: keep-alive\r\n" |
| 8248 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8249 | }; |
| 8250 | |
| 8251 | // Sever accepts the authorization. |
| 8252 | MockRead data_reads2[] = { |
| 8253 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8254 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8255 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8256 | }; |
| 8257 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8258 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8259 | data_writes1, arraysize(data_writes1)); |
| 8260 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8261 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8263 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8265 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8266 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8267 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8268 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8269 | |
| 8270 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8271 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8273 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8274 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8275 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8277 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8278 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8279 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8281 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8282 | ASSERT_TRUE(response); |
| 8283 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8284 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8285 | } |
| 8286 | |
| 8287 | // ------------------------------------------------------------------------ |
| 8288 | |
| 8289 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8290 | // cached identity. Should invalidate and re-prompt. |
| 8291 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8292 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8294 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8295 | request.traffic_annotation = |
| 8296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8299 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8300 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8301 | MockWrite( |
| 8302 | "GET /p/q/t HTTP/1.1\r\n" |
| 8303 | "Host: www.example.org\r\n" |
| 8304 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8305 | }; |
| 8306 | |
| 8307 | MockRead data_reads1[] = { |
| 8308 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8309 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8310 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8311 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8312 | }; |
| 8313 | |
| 8314 | // Resend with authorization from cache for MyRealm. |
| 8315 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8316 | MockWrite( |
| 8317 | "GET /p/q/t HTTP/1.1\r\n" |
| 8318 | "Host: www.example.org\r\n" |
| 8319 | "Connection: keep-alive\r\n" |
| 8320 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8321 | }; |
| 8322 | |
| 8323 | // Sever rejects the authorization. |
| 8324 | MockRead data_reads2[] = { |
| 8325 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8326 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8327 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8328 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8329 | }; |
| 8330 | |
| 8331 | // At this point we should prompt for new credentials for MyRealm. |
| 8332 | // Restart with username=foo3, password=foo4. |
| 8333 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8334 | MockWrite( |
| 8335 | "GET /p/q/t HTTP/1.1\r\n" |
| 8336 | "Host: www.example.org\r\n" |
| 8337 | "Connection: keep-alive\r\n" |
| 8338 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8339 | }; |
| 8340 | |
| 8341 | // Sever accepts the authorization. |
| 8342 | MockRead data_reads3[] = { |
| 8343 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8344 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8345 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8346 | }; |
| 8347 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8348 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8349 | data_writes1, arraysize(data_writes1)); |
| 8350 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8351 | data_writes2, arraysize(data_writes2)); |
| 8352 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8353 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8354 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8355 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8356 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8357 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8358 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8359 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8360 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8361 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8362 | |
| 8363 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8366 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8367 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8370 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8371 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8372 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8374 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8375 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8376 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8378 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8379 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8380 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8381 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8383 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8384 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8387 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8388 | ASSERT_TRUE(response); |
| 8389 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8390 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8391 | } |
| 8392 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8393 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8394 | // Tests that nonce count increments when multiple auth attempts |
| 8395 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8396 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8397 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8398 | new HttpAuthHandlerDigest::Factory(); |
| 8399 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8400 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8401 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8402 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8404 | |
| 8405 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8406 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8407 | HttpRequestInfo request; |
| 8408 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8409 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8410 | request.traffic_annotation = |
| 8411 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8414 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8415 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8416 | MockWrite( |
| 8417 | "GET /x/y/z HTTP/1.1\r\n" |
| 8418 | "Host: www.example.org\r\n" |
| 8419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8420 | }; |
| 8421 | |
| 8422 | MockRead data_reads1[] = { |
| 8423 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8424 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8425 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8426 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8427 | }; |
| 8428 | |
| 8429 | // Resend with authorization (username=foo, password=bar) |
| 8430 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8431 | MockWrite( |
| 8432 | "GET /x/y/z HTTP/1.1\r\n" |
| 8433 | "Host: www.example.org\r\n" |
| 8434 | "Connection: keep-alive\r\n" |
| 8435 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8436 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8437 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8438 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8439 | }; |
| 8440 | |
| 8441 | // Sever accepts the authorization. |
| 8442 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8443 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8445 | }; |
| 8446 | |
| 8447 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8448 | data_writes1, arraysize(data_writes1)); |
| 8449 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8450 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8451 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8452 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8454 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8455 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8456 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8458 | |
| 8459 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8460 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8463 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8464 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8466 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8468 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8469 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8471 | |
| 8472 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8475 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8476 | ASSERT_TRUE(response); |
| 8477 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8478 | } |
| 8479 | |
| 8480 | // ------------------------------------------------------------------------ |
| 8481 | |
| 8482 | // Transaction 2: Request another resource in digestive's protection space. |
| 8483 | // This will preemptively add an Authorization header which should have an |
| 8484 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8485 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8486 | HttpRequestInfo request; |
| 8487 | request.method = "GET"; |
| 8488 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8489 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8490 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8491 | request.traffic_annotation = |
| 8492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8495 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8496 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8497 | MockWrite( |
| 8498 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8499 | "Host: www.example.org\r\n" |
| 8500 | "Connection: keep-alive\r\n" |
| 8501 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8502 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8503 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8504 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8505 | }; |
| 8506 | |
| 8507 | // Sever accepts the authorization. |
| 8508 | MockRead data_reads1[] = { |
| 8509 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8510 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8511 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8512 | }; |
| 8513 | |
| 8514 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8515 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8516 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8518 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8519 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8520 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8522 | |
| 8523 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8524 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8526 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8527 | ASSERT_TRUE(response); |
| 8528 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8529 | } |
| 8530 | } |
| 8531 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8532 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8533 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8534 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8537 | |
| 8538 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8539 | trans.read_buf_ = new IOBuffer(15); |
| 8540 | trans.read_buf_len_ = 15; |
| 8541 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8542 | |
| 8543 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8544 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8545 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8546 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8547 | response->response_time = base::Time::Now(); |
| 8548 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8549 | |
| 8550 | { // Setup state for response_.vary_data |
| 8551 | HttpRequestInfo request; |
| 8552 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8553 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8554 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8555 | request.extra_headers.SetHeader("Foo", "1"); |
| 8556 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8557 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8558 | } |
| 8559 | |
| 8560 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8561 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8562 | |
| 8563 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8564 | EXPECT_FALSE(trans.read_buf_); |
| 8565 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8566 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8567 | EXPECT_FALSE(response->auth_challenge); |
| 8568 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8569 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8570 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8571 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8572 | } |
| 8573 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8574 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8575 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8576 | HttpRequestInfo request; |
| 8577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8578 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8579 | request.traffic_annotation = |
| 8580 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8584 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8585 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8586 | MockWrite( |
| 8587 | "GET / HTTP/1.1\r\n" |
| 8588 | "Host: www.example.org\r\n" |
| 8589 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8590 | }; |
| 8591 | |
| 8592 | MockRead data_reads[] = { |
| 8593 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8594 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8595 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8596 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8597 | }; |
| 8598 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8599 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8600 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8601 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8602 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8603 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8604 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8605 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8609 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8610 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8611 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8612 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8614 | |
| 8615 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8616 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8618 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8620 | |
| 8621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8622 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8625 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8626 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8627 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8628 | } |
| 8629 | |
| 8630 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8631 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8632 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8633 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8634 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8635 | |
| 8636 | HttpRequestInfo request; |
| 8637 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8638 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8639 | request.traffic_annotation = |
| 8640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8641 | |
| 8642 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8643 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8644 | "Host: www.example.org:443\r\n" |
| 8645 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8646 | }; |
| 8647 | |
| 8648 | MockRead proxy_reads[] = { |
| 8649 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8650 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8651 | }; |
| 8652 | |
| 8653 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8654 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8655 | "Host: www.example.org:443\r\n" |
| 8656 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8657 | MockWrite("GET / HTTP/1.1\r\n" |
| 8658 | "Host: www.example.org\r\n" |
| 8659 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8660 | }; |
| 8661 | |
| 8662 | MockRead data_reads[] = { |
| 8663 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8664 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8665 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8666 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8667 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8668 | }; |
| 8669 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8670 | StaticSocketDataProvider ssl_bad_certificate( |
| 8671 | proxy_reads, arraysize(proxy_reads), |
| 8672 | proxy_writes, arraysize(proxy_writes)); |
| 8673 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8674 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8675 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8676 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8677 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8678 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8679 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8680 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8682 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8683 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8684 | |
| 8685 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8686 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8690 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8691 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8693 | |
| 8694 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8695 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8697 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8699 | |
| 8700 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8703 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8704 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8705 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8706 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8707 | } |
| 8708 | } |
| 8709 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8710 | |
| 8711 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8712 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8713 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8714 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8715 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8716 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8717 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8718 | |
| 8719 | HttpRequestInfo request; |
| 8720 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8721 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8722 | request.traffic_annotation = |
| 8723 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8724 | |
| 8725 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8726 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8727 | "Host: www.example.org:443\r\n" |
| 8728 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8729 | MockWrite("GET / HTTP/1.1\r\n" |
| 8730 | "Host: www.example.org\r\n" |
| 8731 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8732 | }; |
| 8733 | |
| 8734 | MockRead data_reads[] = { |
| 8735 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8736 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8737 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8738 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8740 | }; |
| 8741 | |
| 8742 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8743 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8744 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8745 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8746 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8751 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8755 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8756 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8758 | |
| 8759 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8760 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8761 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8762 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8763 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8764 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8765 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8766 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8767 | EXPECT_EQ(200, response->headers->response_code()); |
| 8768 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8769 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8770 | |
| 8771 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8772 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8773 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8774 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8775 | } |
| 8776 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8777 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8778 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8779 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8780 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8781 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8782 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8783 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8784 | |
| 8785 | HttpRequestInfo request; |
| 8786 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8787 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8788 | request.traffic_annotation = |
| 8789 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8790 | |
| 8791 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8792 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8793 | "Host: www.example.org:443\r\n" |
| 8794 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8795 | }; |
| 8796 | |
| 8797 | MockRead data_reads[] = { |
| 8798 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8799 | MockRead("Location: http://login.example.com/\r\n"), |
| 8800 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8802 | }; |
| 8803 | |
| 8804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8805 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8806 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8807 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8811 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8813 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8816 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8818 | |
| 8819 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8820 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8821 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8822 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8823 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8824 | |
| 8825 | EXPECT_EQ(302, response->headers->response_code()); |
| 8826 | std::string url; |
| 8827 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8828 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8829 | |
| 8830 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8831 | // timing for the proxy connection instead of the connection to the host, |
| 8832 | // and no send / receive times. |
| 8833 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8834 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8835 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8836 | |
| 8837 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8838 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8839 | |
| 8840 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8841 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8842 | load_timing_info.proxy_resolve_end); |
| 8843 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8844 | load_timing_info.connect_timing.connect_start); |
| 8845 | ExpectConnectTimingHasTimes( |
| 8846 | load_timing_info.connect_timing, |
| 8847 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8848 | |
| 8849 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8850 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8851 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8852 | } |
| 8853 | |
| 8854 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8855 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8856 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8857 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8858 | |
| 8859 | HttpRequestInfo request; |
| 8860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8861 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8862 | request.traffic_annotation = |
| 8863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8864 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8865 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8867 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8868 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8869 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8870 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8871 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8872 | }; |
| 8873 | |
| 8874 | static const char* const kExtraHeaders[] = { |
| 8875 | "location", |
| 8876 | "http://login.example.com/", |
| 8877 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8878 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8879 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8880 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8881 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8882 | }; |
| 8883 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8884 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8885 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8886 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8887 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8888 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8890 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8892 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8893 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8896 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8897 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8899 | |
| 8900 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8901 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8902 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8903 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8904 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8905 | |
| 8906 | EXPECT_EQ(302, response->headers->response_code()); |
| 8907 | std::string url; |
| 8908 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8909 | EXPECT_EQ("http://login.example.com/", url); |
| 8910 | } |
| 8911 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8912 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8913 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8914 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8915 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8916 | |
| 8917 | HttpRequestInfo request; |
| 8918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8919 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8920 | request.traffic_annotation = |
| 8921 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8922 | |
| 8923 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8924 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8925 | "Host: www.example.org:443\r\n" |
| 8926 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8927 | }; |
| 8928 | |
| 8929 | MockRead data_reads[] = { |
| 8930 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8931 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8932 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8933 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8934 | }; |
| 8935 | |
| 8936 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8937 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8938 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8939 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8943 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8947 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8948 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8950 | |
| 8951 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8952 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8953 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8954 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8955 | } |
| 8956 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8957 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8958 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8959 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8960 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8961 | |
| 8962 | HttpRequestInfo request; |
| 8963 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8964 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8965 | request.traffic_annotation = |
| 8966 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8967 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8968 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8969 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8970 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8971 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8972 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8973 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8974 | }; |
| 8975 | |
| 8976 | static const char* const kExtraHeaders[] = { |
| 8977 | "location", |
| 8978 | "http://login.example.com/", |
| 8979 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8980 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8981 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8982 | SpdySerializedFrame body( |
| 8983 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8984 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8985 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8986 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8987 | }; |
| 8988 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8989 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8990 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8991 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8992 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8993 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8997 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9004 | |
| 9005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9006 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9007 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9008 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9009 | } |
| 9010 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9011 | // Test the request-challenge-retry sequence for basic auth, through |
| 9012 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9013 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9014 | HttpRequestInfo request; |
| 9015 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9016 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9017 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9018 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9019 | request.traffic_annotation = |
| 9020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9021 | |
| 9022 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9023 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9024 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9025 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9026 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9027 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9029 | |
| 9030 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9031 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9032 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9033 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 9034 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9035 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9037 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9038 | // be issuing -- the final header line contains the credentials. |
| 9039 | const char* const kAuthCredentials[] = { |
| 9040 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9041 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9042 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 9043 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9044 | HostPortPair("www.example.org", 443))); |
| 9045 | // fetch https://www.example.org/ via HTTP |
| 9046 | const char get[] = |
| 9047 | "GET / HTTP/1.1\r\n" |
| 9048 | "Host: www.example.org\r\n" |
| 9049 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9050 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9051 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9052 | |
| 9053 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9054 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9055 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9056 | }; |
| 9057 | |
| 9058 | // The proxy responds to the connect with a 407, using a persistent |
| 9059 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9060 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9061 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9062 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9063 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9064 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9065 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9066 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9067 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9068 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9069 | "Content-Length: 5\r\n\r\n"; |
| 9070 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9071 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9072 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9073 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9074 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9075 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9076 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9077 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9078 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9079 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9080 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9081 | }; |
| 9082 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9083 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9084 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9085 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9086 | // Negotiate SPDY to the proxy |
| 9087 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9088 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9089 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9090 | // Vanilla SSL to the server |
| 9091 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9092 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9093 | |
| 9094 | TestCompletionCallback callback1; |
| 9095 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9096 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9097 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9098 | |
| 9099 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9101 | |
| 9102 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9103 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9104 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9105 | log.GetEntries(&entries); |
| 9106 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9107 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9108 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9109 | ExpectLogContainsSomewhere( |
| 9110 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9111 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9112 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9113 | |
| 9114 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9115 | ASSERT_TRUE(response); |
| 9116 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9117 | EXPECT_EQ(407, response->headers->response_code()); |
| 9118 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9119 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9120 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9121 | |
| 9122 | TestCompletionCallback callback2; |
| 9123 | |
| 9124 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9125 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9127 | |
| 9128 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9130 | |
| 9131 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9132 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9133 | |
| 9134 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9135 | EXPECT_EQ(200, response->headers->response_code()); |
| 9136 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9137 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9138 | |
| 9139 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9140 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9141 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9142 | LoadTimingInfo load_timing_info; |
| 9143 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9144 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9145 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9146 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9147 | trans.reset(); |
| 9148 | session->CloseAllConnections(); |
| 9149 | } |
| 9150 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9151 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9152 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9153 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9154 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9155 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9156 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9157 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9158 | HttpRequestInfo request; |
| 9159 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9160 | request.traffic_annotation = |
| 9161 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9162 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9163 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9164 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9165 | push_request.method = "GET"; |
| 9166 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9167 | push_request.traffic_annotation = |
| 9168 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9169 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9170 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9171 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9172 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9173 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9174 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9175 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9176 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9177 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9178 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9180 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9181 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9182 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9183 | SpdySerializedFrame stream2_priority( |
| 9184 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9185 | |
| 9186 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9187 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9188 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9189 | }; |
| 9190 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9191 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 9192 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9193 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9194 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9195 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9196 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9197 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9198 | |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9199 | SpdySerializedFrame stream2_body( |
| 9200 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9201 | |
| 9202 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9203 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9204 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9205 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9206 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9207 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9208 | }; |
| 9209 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9210 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9211 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9212 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9213 | // Negotiate SPDY to the proxy |
| 9214 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9215 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9217 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9218 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9219 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9220 | TestCompletionCallback callback; |
| 9221 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9223 | |
| 9224 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9227 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9228 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9229 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9230 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9231 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9232 | |
| 9233 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9234 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9235 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9236 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9237 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9238 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9239 | |
| 9240 | EXPECT_EQ(200, response->headers->response_code()); |
| 9241 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9242 | |
| 9243 | std::string response_data; |
| 9244 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9246 | EXPECT_EQ("hello!", response_data); |
| 9247 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9248 | LoadTimingInfo load_timing_info; |
| 9249 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9250 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9251 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9252 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9253 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9254 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9255 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9256 | |
| 9257 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9259 | EXPECT_EQ("pushed", response_data); |
| 9260 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9261 | LoadTimingInfo push_load_timing_info; |
| 9262 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9263 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9264 | // The transactions should share a socket ID, despite being for different |
| 9265 | // origins. |
| 9266 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9267 | push_load_timing_info.socket_log_id); |
| 9268 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9269 | trans.reset(); |
| 9270 | push_trans.reset(); |
| 9271 | session->CloseAllConnections(); |
| 9272 | } |
| 9273 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9274 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9275 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9276 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9277 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9278 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9279 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9280 | HttpRequestInfo request; |
| 9281 | |
| 9282 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9283 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9284 | request.traffic_annotation = |
| 9285 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9286 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9287 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9288 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9289 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9290 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9291 | |
| 9292 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9293 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9296 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9297 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9298 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9299 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9300 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 9301 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9302 | |
| 9303 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9304 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9305 | }; |
| 9306 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9307 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9308 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9309 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9310 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9311 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9312 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9313 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9314 | |
| 9315 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9316 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9317 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9318 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9319 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9320 | }; |
| 9321 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9322 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9323 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9324 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9325 | // Negotiate SPDY to the proxy |
| 9326 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9327 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9329 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9330 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9331 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9332 | TestCompletionCallback callback; |
| 9333 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9335 | |
| 9336 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9339 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9340 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9341 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9342 | |
| 9343 | EXPECT_EQ(200, response->headers->response_code()); |
| 9344 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9345 | |
| 9346 | std::string response_data; |
| 9347 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9348 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9349 | EXPECT_EQ("hello!", response_data); |
| 9350 | |
| 9351 | trans.reset(); |
| 9352 | session->CloseAllConnections(); |
| 9353 | } |
| 9354 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9355 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9356 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9357 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9358 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9359 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9360 | proxy_delegate->set_trusted_spdy_proxy( |
| 9361 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9362 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9363 | HttpRequestInfo request; |
| 9364 | |
| 9365 | request.method = "GET"; |
| 9366 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9367 | request.traffic_annotation = |
| 9368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9369 | |
| 9370 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9371 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9372 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9373 | BoundTestNetLog log; |
| 9374 | session_deps_.net_log = log.bound().net_log(); |
| 9375 | |
| 9376 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9377 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9378 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9380 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9381 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9382 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9383 | SpdySerializedFrame stream2_priority( |
| 9384 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9385 | |
| 9386 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9387 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9388 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9389 | }; |
| 9390 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9391 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9392 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9393 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9394 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9395 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9396 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9397 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9398 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9399 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9400 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9401 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9402 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9403 | |
| 9404 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9405 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9406 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9407 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9408 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9409 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9410 | }; |
| 9411 | |
| 9412 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9413 | arraysize(spdy_writes)); |
| 9414 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9415 | // Negotiate SPDY to the proxy |
| 9416 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9417 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9419 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9420 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9421 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9422 | TestCompletionCallback callback; |
| 9423 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9425 | |
| 9426 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9427 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9428 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9429 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9430 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9431 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9432 | |
| 9433 | EXPECT_EQ(200, response->headers->response_code()); |
| 9434 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9435 | |
| 9436 | std::string response_data; |
| 9437 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9438 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9439 | EXPECT_EQ("hello!", response_data); |
| 9440 | |
| 9441 | trans.reset(); |
| 9442 | session->CloseAllConnections(); |
| 9443 | } |
| 9444 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9445 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9446 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9447 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9448 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9449 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9450 | |
| 9451 | HttpRequestInfo request; |
| 9452 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9453 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9454 | request.traffic_annotation = |
| 9455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9456 | |
| 9457 | // Attempt to fetch the URL from a server with a bad cert |
| 9458 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9460 | "Host: www.example.org:443\r\n" |
| 9461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9462 | }; |
| 9463 | |
| 9464 | MockRead bad_cert_reads[] = { |
| 9465 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9466 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9467 | }; |
| 9468 | |
| 9469 | // Attempt to fetch the URL with a good cert |
| 9470 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9471 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9472 | "Host: www.example.org:443\r\n" |
| 9473 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9474 | MockWrite("GET / HTTP/1.1\r\n" |
| 9475 | "Host: www.example.org\r\n" |
| 9476 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9477 | }; |
| 9478 | |
| 9479 | MockRead good_cert_reads[] = { |
| 9480 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9481 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9482 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9483 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9484 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9485 | }; |
| 9486 | |
| 9487 | StaticSocketDataProvider ssl_bad_certificate( |
| 9488 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9489 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9490 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9491 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9492 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9493 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9494 | |
| 9495 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9497 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9499 | |
| 9500 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9502 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9504 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9505 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9509 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9510 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9511 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9512 | |
| 9513 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9514 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9516 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9518 | |
| 9519 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9520 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9522 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9523 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9524 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9525 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9526 | } |
| 9527 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9528 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9529 | HttpRequestInfo request; |
| 9530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9531 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9532 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9533 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9534 | request.traffic_annotation = |
| 9535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9536 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9539 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9540 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9541 | MockWrite( |
| 9542 | "GET / HTTP/1.1\r\n" |
| 9543 | "Host: www.example.org\r\n" |
| 9544 | "Connection: keep-alive\r\n" |
| 9545 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9546 | }; |
| 9547 | |
| 9548 | // Lastly, the server responds with the actual content. |
| 9549 | MockRead data_reads[] = { |
| 9550 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9551 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9552 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9553 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9554 | }; |
| 9555 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9556 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9557 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9558 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9560 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9561 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9562 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9564 | |
| 9565 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9566 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9567 | } |
| 9568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9569 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9570 | HttpRequestInfo request; |
| 9571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9572 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9573 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9574 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9575 | request.traffic_annotation = |
| 9576 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9577 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9578 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9579 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9582 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9583 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9584 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9585 | "Host: www.example.org:443\r\n" |
| 9586 | "Proxy-Connection: keep-alive\r\n" |
| 9587 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9588 | }; |
| 9589 | MockRead data_reads[] = { |
| 9590 | // Return an error, so the transaction stops here (this test isn't |
| 9591 | // interested in the rest). |
| 9592 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9593 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9594 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9595 | }; |
| 9596 | |
| 9597 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9598 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9599 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9600 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9601 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9602 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9603 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9605 | |
| 9606 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9607 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9608 | } |
| 9609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9610 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9611 | HttpRequestInfo request; |
| 9612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9613 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9614 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9615 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9616 | request.traffic_annotation = |
| 9617 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9621 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9622 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9623 | MockWrite( |
| 9624 | "GET / HTTP/1.1\r\n" |
| 9625 | "Host: www.example.org\r\n" |
| 9626 | "Connection: keep-alive\r\n" |
| 9627 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9628 | }; |
| 9629 | |
| 9630 | // Lastly, the server responds with the actual content. |
| 9631 | MockRead data_reads[] = { |
| 9632 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9633 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9634 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9635 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9636 | }; |
| 9637 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9638 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9639 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9641 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9642 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9646 | |
| 9647 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9648 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9649 | } |
| 9650 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9651 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9652 | HttpRequestInfo request; |
| 9653 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9654 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9655 | request.traffic_annotation = |
| 9656 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9659 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9660 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9661 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9662 | MockWrite( |
| 9663 | "POST / HTTP/1.1\r\n" |
| 9664 | "Host: www.example.org\r\n" |
| 9665 | "Connection: keep-alive\r\n" |
| 9666 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9667 | }; |
| 9668 | |
| 9669 | // Lastly, the server responds with the actual content. |
| 9670 | MockRead data_reads[] = { |
| 9671 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9673 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9674 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9675 | }; |
| 9676 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9677 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9678 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9679 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9681 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9682 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9683 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9685 | |
| 9686 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9687 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9688 | } |
| 9689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9690 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9691 | HttpRequestInfo request; |
| 9692 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9693 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9694 | request.traffic_annotation = |
| 9695 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9696 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9698 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9699 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9700 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9701 | MockWrite( |
| 9702 | "PUT / HTTP/1.1\r\n" |
| 9703 | "Host: www.example.org\r\n" |
| 9704 | "Connection: keep-alive\r\n" |
| 9705 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9706 | }; |
| 9707 | |
| 9708 | // Lastly, the server responds with the actual content. |
| 9709 | MockRead data_reads[] = { |
| 9710 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9711 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9712 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9714 | }; |
| 9715 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9716 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9717 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9718 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9720 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9721 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9722 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9724 | |
| 9725 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9726 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9727 | } |
| 9728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9729 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9730 | HttpRequestInfo request; |
| 9731 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9732 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9733 | request.traffic_annotation = |
| 9734 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9738 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9739 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9740 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9741 | "Host: www.example.org\r\n" |
| 9742 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9743 | }; |
| 9744 | |
| 9745 | // Lastly, the server responds with the actual content. |
| 9746 | MockRead data_reads[] = { |
| 9747 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9749 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9750 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9751 | }; |
| 9752 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9753 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9754 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9757 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9758 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9759 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9761 | |
| 9762 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9764 | } |
| 9765 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9766 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9767 | HttpRequestInfo request; |
| 9768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9769 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9770 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9771 | request.traffic_annotation = |
| 9772 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9775 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9776 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9777 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9778 | MockWrite( |
| 9779 | "GET / HTTP/1.1\r\n" |
| 9780 | "Host: www.example.org\r\n" |
| 9781 | "Connection: keep-alive\r\n" |
| 9782 | "Pragma: no-cache\r\n" |
| 9783 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9784 | }; |
| 9785 | |
| 9786 | // Lastly, the server responds with the actual content. |
| 9787 | MockRead data_reads[] = { |
| 9788 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9789 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9790 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9791 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9792 | }; |
| 9793 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9794 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9795 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9798 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9800 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9802 | |
| 9803 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9804 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9805 | } |
| 9806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9807 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9808 | HttpRequestInfo request; |
| 9809 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9810 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9811 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9812 | request.traffic_annotation = |
| 9813 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9817 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9818 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9819 | MockWrite( |
| 9820 | "GET / HTTP/1.1\r\n" |
| 9821 | "Host: www.example.org\r\n" |
| 9822 | "Connection: keep-alive\r\n" |
| 9823 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9824 | }; |
| 9825 | |
| 9826 | // Lastly, the server responds with the actual content. |
| 9827 | MockRead data_reads[] = { |
| 9828 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9829 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9830 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9832 | }; |
| 9833 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9834 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9835 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9836 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9838 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9839 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9840 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9842 | |
| 9843 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9845 | } |
| 9846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9847 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9848 | HttpRequestInfo request; |
| 9849 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9850 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9851 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9852 | request.traffic_annotation = |
| 9853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9854 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9857 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9858 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9859 | MockWrite( |
| 9860 | "GET / HTTP/1.1\r\n" |
| 9861 | "Host: www.example.org\r\n" |
| 9862 | "Connection: keep-alive\r\n" |
| 9863 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9864 | }; |
| 9865 | |
| 9866 | // Lastly, the server responds with the actual content. |
| 9867 | MockRead data_reads[] = { |
| 9868 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9872 | }; |
| 9873 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9874 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9875 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9876 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9878 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9880 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9882 | |
| 9883 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9885 | } |
| 9886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9887 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9888 | HttpRequestInfo request; |
| 9889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9890 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9891 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9892 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9893 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9894 | request.traffic_annotation = |
| 9895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9899 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9900 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9901 | MockWrite( |
| 9902 | "GET / HTTP/1.1\r\n" |
| 9903 | "Host: www.example.org\r\n" |
| 9904 | "Connection: keep-alive\r\n" |
| 9905 | "referer: www.foo.com\r\n" |
| 9906 | "hEllo: Kitty\r\n" |
| 9907 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9908 | }; |
| 9909 | |
| 9910 | // Lastly, the server responds with the actual content. |
| 9911 | MockRead data_reads[] = { |
| 9912 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9913 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9914 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9916 | }; |
| 9917 | |
| 9918 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9919 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9920 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9922 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9926 | |
| 9927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9929 | } |
| 9930 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9931 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9932 | HttpRequestInfo request; |
| 9933 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9934 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9935 | request.traffic_annotation = |
| 9936 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9937 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9938 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9939 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9940 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9941 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9942 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9946 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9947 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9948 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9949 | |
| 9950 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9951 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9952 | MockWrite( |
| 9953 | "GET / HTTP/1.1\r\n" |
| 9954 | "Host: www.example.org\r\n" |
| 9955 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9956 | |
| 9957 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9958 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9959 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9960 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9961 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9962 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9963 | }; |
| 9964 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9965 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9966 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9968 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9969 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9971 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9973 | |
| 9974 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9975 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9977 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9978 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9979 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9980 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9981 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9982 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9983 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9984 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9985 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9986 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9987 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9988 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9989 | EXPECT_EQ("Payload", response_text); |
| 9990 | } |
| 9991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9992 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9993 | HttpRequestInfo request; |
| 9994 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9995 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9996 | request.traffic_annotation = |
| 9997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9998 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9999 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10000 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10001 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10002 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10003 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10006 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10007 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10008 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10009 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10010 | |
| 10011 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10012 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 10013 | arraysize(write_buffer)), |
| 10014 | MockWrite( |
| 10015 | "GET / HTTP/1.1\r\n" |
| 10016 | "Host: www.example.org\r\n" |
| 10017 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10018 | |
| 10019 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10020 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10021 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10022 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10023 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10024 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10025 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10026 | }; |
| 10027 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10028 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10029 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10030 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10031 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10032 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10033 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[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 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10043 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10044 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10045 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10046 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10049 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10050 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10051 | |
| 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, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10059 | HttpRequestInfo request; |
| 10060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10061 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10062 | request.traffic_annotation = |
| 10063 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10064 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10065 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10066 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10067 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10068 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10069 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10070 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10071 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10072 | |
| 10073 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10074 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10075 | |
| 10076 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10077 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 10078 | MockWrite( |
| 10079 | "GET / HTTP/1.1\r\n" |
| 10080 | "Host: www.example.org\r\n" |
| 10081 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10082 | |
| 10083 | MockRead data_reads[] = { |
| 10084 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 10085 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10086 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10087 | MockRead("Payload"), |
| 10088 | MockRead(SYNCHRONOUS, OK) |
| 10089 | }; |
| 10090 | |
| 10091 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10092 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10093 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10094 | |
| 10095 | TestCompletionCallback callback; |
| 10096 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10097 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10099 | |
| 10100 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10101 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10104 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10105 | |
| 10106 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10107 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10108 | TestLoadTimingNotReused(load_timing_info, |
| 10109 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10110 | |
| 10111 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10112 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10114 | EXPECT_EQ("Payload", response_text); |
| 10115 | } |
| 10116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10117 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10118 | HttpRequestInfo request; |
| 10119 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10120 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10121 | request.traffic_annotation = |
| 10122 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10123 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10124 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10125 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10126 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10127 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10128 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10132 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10133 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10134 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10135 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10136 | 0x05, // Version |
| 10137 | 0x01, // Command (CONNECT) |
| 10138 | 0x00, // Reserved. |
| 10139 | 0x03, // Address type (DOMAINNAME). |
| 10140 | 0x0F, // Length of domain (15) |
| 10141 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10142 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10143 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10144 | const char kSOCKS5OkResponse[] = |
| 10145 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10146 | |
| 10147 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10148 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10149 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10150 | MockWrite( |
| 10151 | "GET / HTTP/1.1\r\n" |
| 10152 | "Host: www.example.org\r\n" |
| 10153 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10154 | |
| 10155 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10156 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10157 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10158 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10159 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10160 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10161 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10162 | }; |
| 10163 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10164 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10165 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10166 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10167 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10168 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10169 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10170 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10172 | |
| 10173 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10174 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10176 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10177 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10178 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10179 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10180 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10181 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10182 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10183 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10184 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10185 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10186 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10188 | EXPECT_EQ("Payload", response_text); |
| 10189 | } |
| 10190 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10191 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10192 | HttpRequestInfo request; |
| 10193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10194 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10195 | request.traffic_annotation = |
| 10196 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10197 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10198 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10199 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10200 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10201 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10202 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10203 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10204 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10205 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10206 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10207 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10208 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10209 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10210 | 0x05, // Version |
| 10211 | 0x01, // Command (CONNECT) |
| 10212 | 0x00, // Reserved. |
| 10213 | 0x03, // Address type (DOMAINNAME). |
| 10214 | 0x0F, // Length of domain (15) |
| 10215 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10216 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10217 | }; |
| 10218 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10219 | const char kSOCKS5OkResponse[] = |
| 10220 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10221 | |
| 10222 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10223 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10224 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10225 | arraysize(kSOCKS5OkRequest)), |
| 10226 | MockWrite( |
| 10227 | "GET / HTTP/1.1\r\n" |
| 10228 | "Host: www.example.org\r\n" |
| 10229 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10230 | |
| 10231 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10232 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10233 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10234 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10235 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10236 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10237 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10238 | }; |
| 10239 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10240 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10241 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10242 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10243 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10244 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10247 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10249 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10251 | |
| 10252 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10255 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10256 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10257 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10258 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10259 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10260 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10261 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10262 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10263 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10264 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10265 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10267 | EXPECT_EQ("Payload", response_text); |
| 10268 | } |
| 10269 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10270 | namespace { |
| 10271 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10272 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10273 | |
| 10274 | struct GroupNameTest { |
| 10275 | std::string proxy_server; |
| 10276 | std::string url; |
| 10277 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10278 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10279 | }; |
| 10280 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10281 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10282 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10284 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10285 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10286 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10287 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10288 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10289 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10290 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10291 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10292 | |
| 10293 | return session; |
| 10294 | } |
| 10295 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10296 | int GroupNameTransactionHelper(const std::string& url, |
| 10297 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10298 | HttpRequestInfo request; |
| 10299 | request.method = "GET"; |
| 10300 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10301 | request.traffic_annotation = |
| 10302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10306 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10307 | |
| 10308 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10309 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10310 | } |
| 10311 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10312 | } // namespace |
| 10313 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10314 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10315 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10316 | { |
| 10317 | "", // unused |
| 10318 | "http://www.example.org/direct", |
| 10319 | "www.example.org:80", |
| 10320 | false, |
| 10321 | }, |
| 10322 | { |
| 10323 | "", // unused |
| 10324 | "http://[2001:1418:13:1::25]/direct", |
| 10325 | "[2001:1418:13:1::25]:80", |
| 10326 | false, |
| 10327 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10328 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10329 | // SSL Tests |
| 10330 | { |
| 10331 | "", // unused |
| 10332 | "https://www.example.org/direct_ssl", |
| 10333 | "ssl/www.example.org:443", |
| 10334 | true, |
| 10335 | }, |
| 10336 | { |
| 10337 | "", // unused |
| 10338 | "https://[2001:1418:13:1::25]/direct", |
| 10339 | "ssl/[2001:1418:13:1::25]:443", |
| 10340 | true, |
| 10341 | }, |
| 10342 | { |
| 10343 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10344 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10345 | "ssl/host.with.alternate:443", |
| 10346 | true, |
| 10347 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10348 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10349 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10350 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10351 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10352 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10353 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10354 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10355 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10356 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10357 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10358 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10359 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10360 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10361 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10362 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10363 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10364 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10365 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10366 | |
| 10367 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10368 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10369 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10370 | EXPECT_EQ(tests[i].expected_group_name, |
| 10371 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10372 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10373 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10374 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10375 | } |
| 10376 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10377 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10378 | // When SSL proxy is not in use, socket must be requested from |
| 10379 | // |transport_conn_pool|. |
| 10380 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10381 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10382 | } |
| 10383 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10384 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10385 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10386 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10387 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10388 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10389 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10390 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10391 | // SSL Tests |
| 10392 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10393 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10394 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10395 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10396 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10397 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10398 | "http_proxy", "https://host.with.alternate/direct", |
| 10399 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10400 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10401 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10402 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10403 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10404 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10405 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10406 | }; |
| 10407 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10408 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10409 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10410 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10411 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10412 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10413 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10414 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10415 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10416 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10417 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10418 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10419 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10420 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10421 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10422 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10423 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10424 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10425 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10426 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10427 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10428 | |
| 10429 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10430 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10431 | if (tests[i].ssl) |
| 10432 | EXPECT_EQ(tests[i].expected_group_name, |
| 10433 | ssl_conn_pool->last_group_name_received()); |
| 10434 | else |
| 10435 | EXPECT_EQ(tests[i].expected_group_name, |
| 10436 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10437 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10438 | } |
| 10439 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10440 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10441 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10442 | { |
| 10443 | "socks4://socks_proxy:1080", |
| 10444 | "http://www.example.org/socks4_direct", |
| 10445 | "socks4/www.example.org:80", |
| 10446 | false, |
| 10447 | }, |
| 10448 | { |
| 10449 | "socks5://socks_proxy:1080", |
| 10450 | "http://www.example.org/socks5_direct", |
| 10451 | "socks5/www.example.org:80", |
| 10452 | false, |
| 10453 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10454 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10455 | // SSL Tests |
| 10456 | { |
| 10457 | "socks4://socks_proxy:1080", |
| 10458 | "https://www.example.org/socks4_ssl", |
| 10459 | "socks4/ssl/www.example.org:443", |
| 10460 | true, |
| 10461 | }, |
| 10462 | { |
| 10463 | "socks5://socks_proxy:1080", |
| 10464 | "https://www.example.org/socks5_ssl", |
| 10465 | "socks5/ssl/www.example.org:443", |
| 10466 | true, |
| 10467 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10468 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10469 | { |
| 10470 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10471 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10472 | "socks4/ssl/host.with.alternate:443", |
| 10473 | true, |
| 10474 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10475 | }; |
| 10476 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10477 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10478 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10479 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10480 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10481 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10482 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10483 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10484 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10485 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10486 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10487 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10488 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10489 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10490 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10491 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10492 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10493 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10494 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10495 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10496 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10497 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10499 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10500 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10501 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10502 | if (tests[i].ssl) |
| 10503 | EXPECT_EQ(tests[i].expected_group_name, |
| 10504 | ssl_conn_pool->last_group_name_received()); |
| 10505 | else |
| 10506 | EXPECT_EQ(tests[i].expected_group_name, |
| 10507 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10508 | } |
| 10509 | } |
| 10510 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10511 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10512 | HttpRequestInfo request; |
| 10513 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10514 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10515 | request.traffic_annotation = |
| 10516 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10517 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10518 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10519 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10520 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10521 | // This simulates failure resolving all hostnames; that means we will fail |
| 10522 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10523 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10525 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10532 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10533 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10534 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10535 | } |
| 10536 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10537 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10538 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10539 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10540 | HttpRequestInfo request_info; |
| 10541 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10542 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10543 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10544 | request_info.traffic_annotation = |
| 10545 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10546 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10547 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10548 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10549 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10550 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10552 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10553 | // 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] | 10554 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10555 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10556 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10557 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10558 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10559 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10560 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10562 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10563 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10564 | |
| 10565 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10566 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10567 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10568 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10569 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10570 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10571 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10572 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10573 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10574 | // 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] | 10575 | // we can tell if the next lookup hit the cache, or the "network". |
| 10576 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10577 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10578 | |
| 10579 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10580 | // 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] | 10581 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10582 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10583 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10584 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10585 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10586 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10587 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10588 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10589 | |
| 10590 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10591 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10593 | } |
| 10594 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10595 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10596 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10597 | HttpRequestInfo request; |
| 10598 | request.method = "GET"; |
| 10599 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10600 | request.traffic_annotation = |
| 10601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10602 | |
| 10603 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10604 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10605 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10606 | StaticSocketDataProvider data(NULL, 0, |
| 10607 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10611 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10617 | |
| 10618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10619 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10620 | |
| 10621 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10622 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10623 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10624 | } |
| 10625 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10626 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10627 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10628 | HttpRequestInfo request; |
| 10629 | request.method = "GET"; |
| 10630 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10631 | request.traffic_annotation = |
| 10632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10633 | |
| 10634 | MockRead data_reads[] = { |
| 10635 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10636 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10637 | }; |
| 10638 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10639 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10643 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10645 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10646 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10647 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10649 | |
| 10650 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10651 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10653 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10654 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10655 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10656 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10657 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10658 | |
| 10659 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10660 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10661 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10662 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10663 | |
| 10664 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10665 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10666 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10667 | } |
| 10668 | |
| 10669 | // Make sure that a dropped connection while draining the body for auth |
| 10670 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10671 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10672 | HttpRequestInfo request; |
| 10673 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10674 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10675 | request.traffic_annotation = |
| 10676 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10677 | |
| 10678 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10679 | MockWrite( |
| 10680 | "GET / HTTP/1.1\r\n" |
| 10681 | "Host: www.example.org\r\n" |
| 10682 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10683 | }; |
| 10684 | |
| 10685 | MockRead data_reads1[] = { |
| 10686 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10687 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10688 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10689 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10690 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10691 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10692 | }; |
| 10693 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10694 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10695 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10696 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10698 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10699 | // be issuing -- the final header line contains the credentials. |
| 10700 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10701 | MockWrite( |
| 10702 | "GET / HTTP/1.1\r\n" |
| 10703 | "Host: www.example.org\r\n" |
| 10704 | "Connection: keep-alive\r\n" |
| 10705 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10706 | }; |
| 10707 | |
| 10708 | // Lastly, the server responds with the actual content. |
| 10709 | MockRead data_reads2[] = { |
| 10710 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10711 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10712 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10713 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10714 | }; |
| 10715 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10716 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10717 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10718 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10720 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10721 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10723 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10724 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10725 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10727 | |
| 10728 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10729 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10731 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10732 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10733 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10735 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10737 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10739 | |
| 10740 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10743 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10744 | ASSERT_TRUE(response); |
| 10745 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10746 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10747 | } |
| 10748 | |
| 10749 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10750 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10751 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10752 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10753 | |
| 10754 | HttpRequestInfo request; |
| 10755 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10756 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10757 | request.traffic_annotation = |
| 10758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10759 | |
| 10760 | MockRead proxy_reads[] = { |
| 10761 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10762 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10763 | }; |
| 10764 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10765 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10766 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10767 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10768 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10770 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10771 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10772 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10773 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10777 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10778 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10780 | |
| 10781 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10782 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10783 | } |
| 10784 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10785 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10786 | HttpRequestInfo request; |
| 10787 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10788 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10789 | request.traffic_annotation = |
| 10790 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10791 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10792 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10793 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10794 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10795 | MockRead data_reads[] = { |
| 10796 | 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] | 10797 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10798 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10799 | |
| 10800 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10801 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10803 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10805 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10807 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10808 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10810 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10811 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10812 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10813 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10814 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10815 | |
| 10816 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10817 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10818 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10819 | } |
| 10820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10821 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10822 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10823 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10824 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10825 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10826 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10827 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10828 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10829 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10830 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10831 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10832 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10833 | |
| 10834 | HttpRequestInfo request; |
| 10835 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10836 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10837 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10838 | request.traffic_annotation = |
| 10839 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10840 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10841 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10842 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10843 | |
| 10844 | MockRead data_reads[] = { |
| 10845 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10846 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10847 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10848 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10849 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10850 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10852 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10853 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10854 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10855 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10856 | |
| 10857 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10858 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10861 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10862 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10863 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10864 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10865 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10866 | } |
| 10867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10868 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10869 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10870 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10871 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10872 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10873 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10874 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10875 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10877 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10878 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10879 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10880 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10881 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10882 | |
| 10883 | HttpRequestInfo request; |
| 10884 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10885 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10886 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10887 | request.traffic_annotation = |
| 10888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10889 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10890 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10892 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10893 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10894 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10897 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10898 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10899 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10901 | |
| 10902 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10903 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10904 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10905 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10906 | } |
| 10907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10908 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10909 | class FakeUploadElementReader : public UploadElementReader { |
| 10910 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10911 | FakeUploadElementReader() = default; |
| 10912 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10913 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10914 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10915 | |
| 10916 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10917 | int Init(CompletionOnceCallback callback) override { |
| 10918 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10919 | return ERR_IO_PENDING; |
| 10920 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10921 | uint64_t GetContentLength() const override { return 0; } |
| 10922 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10923 | int Read(IOBuffer* buf, |
| 10924 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10925 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10926 | return ERR_FAILED; |
| 10927 | } |
| 10928 | |
| 10929 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10930 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10931 | }; |
| 10932 | |
| 10933 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10934 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10935 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10936 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10937 | |
| 10938 | HttpRequestInfo request; |
| 10939 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10940 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10941 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10942 | request.traffic_annotation = |
| 10943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10946 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10947 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10948 | |
| 10949 | StaticSocketDataProvider data; |
| 10950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10951 | |
| 10952 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10953 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10955 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10956 | |
| 10957 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10958 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10959 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10960 | |
| 10961 | // Return Init()'s result after the transaction gets destroyed. |
| 10962 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10963 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10964 | } |
| 10965 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10966 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10967 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10968 | HttpRequestInfo request; |
| 10969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10970 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10971 | request.traffic_annotation = |
| 10972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10973 | |
| 10974 | // First transaction will request a resource and receive a Basic challenge |
| 10975 | // with realm="first_realm". |
| 10976 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10977 | MockWrite( |
| 10978 | "GET / HTTP/1.1\r\n" |
| 10979 | "Host: www.example.org\r\n" |
| 10980 | "Connection: keep-alive\r\n" |
| 10981 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10982 | }; |
| 10983 | MockRead data_reads1[] = { |
| 10984 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10985 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10986 | "\r\n"), |
| 10987 | }; |
| 10988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10989 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10990 | // for first_realm. The server will reject and provide a challenge with |
| 10991 | // second_realm. |
| 10992 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10993 | MockWrite( |
| 10994 | "GET / HTTP/1.1\r\n" |
| 10995 | "Host: www.example.org\r\n" |
| 10996 | "Connection: keep-alive\r\n" |
| 10997 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10998 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10999 | }; |
| 11000 | MockRead data_reads2[] = { |
| 11001 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11002 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11003 | "\r\n"), |
| 11004 | }; |
| 11005 | |
| 11006 | // This again fails, and goes back to first_realm. Make sure that the |
| 11007 | // entry is removed from cache. |
| 11008 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11009 | MockWrite( |
| 11010 | "GET / HTTP/1.1\r\n" |
| 11011 | "Host: www.example.org\r\n" |
| 11012 | "Connection: keep-alive\r\n" |
| 11013 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11014 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11015 | }; |
| 11016 | MockRead data_reads3[] = { |
| 11017 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11018 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11019 | "\r\n"), |
| 11020 | }; |
| 11021 | |
| 11022 | // Try one last time (with the correct password) and get the resource. |
| 11023 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11024 | MockWrite( |
| 11025 | "GET / HTTP/1.1\r\n" |
| 11026 | "Host: www.example.org\r\n" |
| 11027 | "Connection: keep-alive\r\n" |
| 11028 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11029 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11030 | }; |
| 11031 | MockRead data_reads4[] = { |
| 11032 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11033 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11034 | "Content-Length: 5\r\n" |
| 11035 | "\r\n" |
| 11036 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11037 | }; |
| 11038 | |
| 11039 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 11040 | data_writes1, arraysize(data_writes1)); |
| 11041 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 11042 | data_writes2, arraysize(data_writes2)); |
| 11043 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 11044 | data_writes3, arraysize(data_writes3)); |
| 11045 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 11046 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11047 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11048 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11049 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11050 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11052 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11055 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11056 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11057 | // Issue the first request with Authorize headers. There should be a |
| 11058 | // password prompt for first_realm waiting to be filled in after the |
| 11059 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11060 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11062 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11063 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11064 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11065 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11066 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11067 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11068 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11069 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11070 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11071 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11072 | |
| 11073 | // Issue the second request with an incorrect password. There should be a |
| 11074 | // password prompt for second_realm waiting to be filled in after the |
| 11075 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11076 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11077 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11078 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11080 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11081 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11082 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11083 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11084 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11085 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11086 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11087 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11088 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11089 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11090 | |
| 11091 | // Issue the third request with another incorrect password. There should be |
| 11092 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11093 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11094 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11095 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11096 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11097 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11099 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11100 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11101 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11102 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11103 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11104 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11105 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11106 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11107 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11108 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11109 | |
| 11110 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11111 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11112 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11113 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11115 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11116 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11117 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11118 | ASSERT_TRUE(response); |
| 11119 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11120 | } |
| 11121 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11122 | // Regression test for https://crbug.com/754395. |
| 11123 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11124 | MockRead data_reads[] = { |
| 11125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11126 | MockRead(kAlternativeServiceHttpHeader), |
| 11127 | MockRead("\r\n"), |
| 11128 | MockRead("hello world"), |
| 11129 | MockRead(SYNCHRONOUS, OK), |
| 11130 | }; |
| 11131 | |
| 11132 | HttpRequestInfo request; |
| 11133 | request.method = "GET"; |
| 11134 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11135 | request.traffic_annotation = |
| 11136 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11137 | |
| 11138 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11140 | |
| 11141 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11142 | ssl.ssl_info.cert = |
| 11143 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11144 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11145 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11147 | |
| 11148 | TestCompletionCallback callback; |
| 11149 | |
| 11150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11152 | |
| 11153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11155 | |
| 11156 | url::SchemeHostPort test_server(request.url); |
| 11157 | HttpServerProperties* http_server_properties = |
| 11158 | session->http_server_properties(); |
| 11159 | EXPECT_TRUE( |
| 11160 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11161 | |
| 11162 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11163 | |
| 11164 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11165 | ASSERT_TRUE(response); |
| 11166 | ASSERT_TRUE(response->headers); |
| 11167 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11168 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11169 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11170 | |
| 11171 | std::string response_data; |
| 11172 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11173 | EXPECT_EQ("hello world", response_data); |
| 11174 | |
| 11175 | EXPECT_TRUE( |
| 11176 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11177 | } |
| 11178 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11179 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11180 | MockRead data_reads[] = { |
| 11181 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11182 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11183 | MockRead("\r\n"), |
| 11184 | MockRead("hello world"), |
| 11185 | MockRead(SYNCHRONOUS, OK), |
| 11186 | }; |
| 11187 | |
| 11188 | HttpRequestInfo request; |
| 11189 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11190 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11191 | request.traffic_annotation = |
| 11192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11193 | |
| 11194 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11196 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11197 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11198 | ssl.ssl_info.cert = |
| 11199 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11200 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11202 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11203 | TestCompletionCallback callback; |
| 11204 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11206 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11207 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11208 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11210 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11211 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11212 | HttpServerProperties* http_server_properties = |
| 11213 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11214 | EXPECT_TRUE( |
| 11215 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11216 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11217 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11218 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11219 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11220 | ASSERT_TRUE(response); |
| 11221 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11222 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11223 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11224 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11225 | |
| 11226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11227 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11228 | EXPECT_EQ("hello world", response_data); |
| 11229 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11230 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11231 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11232 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11233 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11234 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11235 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11236 | } |
| 11237 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11238 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11239 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11240 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11241 | MockRead data_reads[] = { |
| 11242 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11243 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11244 | MockRead("\r\n"), |
| 11245 | MockRead("hello world"), |
| 11246 | MockRead(SYNCHRONOUS, OK), |
| 11247 | }; |
| 11248 | |
| 11249 | HttpRequestInfo request; |
| 11250 | request.method = "GET"; |
| 11251 | request.url = GURL("http://www.example.org/"); |
| 11252 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11253 | request.traffic_annotation = |
| 11254 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11255 | |
| 11256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11258 | |
| 11259 | TestCompletionCallback callback; |
| 11260 | |
| 11261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11263 | |
| 11264 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11265 | HttpServerProperties* http_server_properties = |
| 11266 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11267 | EXPECT_TRUE( |
| 11268 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11269 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11270 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11272 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11273 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11274 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11275 | ASSERT_TRUE(response); |
| 11276 | ASSERT_TRUE(response->headers); |
| 11277 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11278 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11279 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11280 | |
| 11281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11282 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11283 | EXPECT_EQ("hello world", response_data); |
| 11284 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11285 | EXPECT_TRUE( |
| 11286 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11287 | } |
| 11288 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11289 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11290 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11291 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11292 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11293 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11294 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11295 | HttpRequestInfo request; |
| 11296 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11297 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11298 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11299 | request.traffic_annotation = |
| 11300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11301 | |
| 11302 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11303 | StaticSocketDataProvider first_data; |
| 11304 | first_data.set_connect_data(mock_connect); |
| 11305 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11306 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11307 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11309 | |
| 11310 | MockRead data_reads[] = { |
| 11311 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11312 | MockRead(ASYNC, OK), |
| 11313 | }; |
| 11314 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11315 | 0); |
| 11316 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11317 | |
| 11318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11319 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11320 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11321 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11322 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11323 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11324 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11325 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11326 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11329 | TestCompletionCallback callback; |
| 11330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11332 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11333 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11334 | } |
| 11335 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11336 | // Regression test for https://crbug.com/615497: |
| 11337 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11338 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11339 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11340 | HttpRequestInfo request; |
| 11341 | request.method = "GET"; |
| 11342 | request.url = GURL("http://www.example.org/"); |
| 11343 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11344 | request.traffic_annotation = |
| 11345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11346 | |
| 11347 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11348 | StaticSocketDataProvider first_data; |
| 11349 | first_data.set_connect_data(mock_connect); |
| 11350 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11351 | |
| 11352 | MockRead data_reads[] = { |
| 11353 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11354 | MockRead(ASYNC, OK), |
| 11355 | }; |
| 11356 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11357 | 0); |
| 11358 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11359 | |
| 11360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11361 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11362 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11363 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11364 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11365 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11366 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11367 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11369 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11370 | TestCompletionCallback callback; |
| 11371 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11372 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11373 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11374 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11375 | } |
| 11376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11377 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11378 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11380 | HttpServerProperties* http_server_properties = |
| 11381 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11382 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11383 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11384 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11385 | http_server_properties->SetQuicAlternativeService( |
| 11386 | test_server, alternative_service, expiration, |
| 11387 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11388 | EXPECT_EQ( |
| 11389 | 1u, |
| 11390 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11391 | |
| 11392 | // Send a clear header. |
| 11393 | MockRead data_reads[] = { |
| 11394 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11395 | MockRead("Alt-Svc: clear\r\n"), |
| 11396 | MockRead("\r\n"), |
| 11397 | MockRead("hello world"), |
| 11398 | MockRead(SYNCHRONOUS, OK), |
| 11399 | }; |
| 11400 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 11401 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11402 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11403 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11404 | ssl.ssl_info.cert = |
| 11405 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11406 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11408 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11409 | HttpRequestInfo request; |
| 11410 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11411 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11412 | request.traffic_annotation = |
| 11413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11414 | |
| 11415 | TestCompletionCallback callback; |
| 11416 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11419 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11420 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11422 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11423 | ASSERT_TRUE(response); |
| 11424 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11425 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11426 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11427 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11428 | |
| 11429 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11430 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11431 | EXPECT_EQ("hello world", response_data); |
| 11432 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11433 | EXPECT_TRUE( |
| 11434 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11435 | } |
| 11436 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11437 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11438 | MockRead data_reads[] = { |
| 11439 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11440 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11441 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11442 | MockRead("hello world"), |
| 11443 | MockRead(SYNCHRONOUS, OK), |
| 11444 | }; |
| 11445 | |
| 11446 | HttpRequestInfo request; |
| 11447 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11448 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11449 | request.traffic_annotation = |
| 11450 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11451 | |
| 11452 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11454 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11455 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11456 | ssl.ssl_info.cert = |
| 11457 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11458 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11460 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11461 | TestCompletionCallback callback; |
| 11462 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11464 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11466 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11468 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11469 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11470 | HttpServerProperties* http_server_properties = |
| 11471 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11472 | EXPECT_TRUE( |
| 11473 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11474 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11475 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11478 | ASSERT_TRUE(response); |
| 11479 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11480 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11481 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11482 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11483 | |
| 11484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11485 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11486 | EXPECT_EQ("hello world", response_data); |
| 11487 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11488 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11489 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11490 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11491 | |
| 11492 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11493 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11494 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11495 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11496 | 1234); |
| 11497 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11498 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11499 | } |
| 11500 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11501 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11502 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11503 | HostPortPair alternative("alternative.example.org", 443); |
| 11504 | std::string origin_url = "https://origin.example.org:443"; |
| 11505 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11506 | |
| 11507 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11508 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11509 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11510 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11511 | |
| 11512 | // HTTP/1.1 data for request. |
| 11513 | MockWrite http_writes[] = { |
| 11514 | MockWrite("GET / HTTP/1.1\r\n" |
| 11515 | "Host: alternative.example.org\r\n" |
| 11516 | "Connection: keep-alive\r\n\r\n"), |
| 11517 | }; |
| 11518 | |
| 11519 | MockRead http_reads[] = { |
| 11520 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11521 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11522 | "Content-Length: 40\r\n\r\n" |
| 11523 | "first HTTP/1.1 response from alternative"), |
| 11524 | }; |
| 11525 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11526 | http_writes, arraysize(http_writes)); |
| 11527 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11528 | |
| 11529 | StaticSocketDataProvider data_refused; |
| 11530 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11531 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11532 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11533 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11535 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11536 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11537 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11538 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11539 | http_server_properties->SetQuicAlternativeService( |
| 11540 | server, alternative_service, expiration, |
| 11541 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11542 | // Mark the QUIC alternative service as broken. |
| 11543 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11544 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11545 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11546 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11547 | request.method = "GET"; |
| 11548 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11549 | request.traffic_annotation = |
| 11550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11551 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11552 | TestCompletionCallback callback; |
| 11553 | NetErrorDetails details; |
| 11554 | EXPECT_FALSE(details.quic_broken); |
| 11555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11556 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11557 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11558 | EXPECT_TRUE(details.quic_broken); |
| 11559 | } |
| 11560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11561 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11562 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11563 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11564 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11565 | std::string origin_url = "https://origin.example.org:443"; |
| 11566 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11567 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11568 | |
| 11569 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11570 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11571 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11573 | |
| 11574 | // HTTP/1.1 data for request. |
| 11575 | MockWrite http_writes[] = { |
| 11576 | MockWrite("GET / HTTP/1.1\r\n" |
| 11577 | "Host: alternative1.example.org\r\n" |
| 11578 | "Connection: keep-alive\r\n\r\n"), |
| 11579 | }; |
| 11580 | |
| 11581 | MockRead http_reads[] = { |
| 11582 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11583 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11584 | "Content-Length: 40\r\n\r\n" |
| 11585 | "first HTTP/1.1 response from alternative1"), |
| 11586 | }; |
| 11587 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11588 | http_writes, arraysize(http_writes)); |
| 11589 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11590 | |
| 11591 | StaticSocketDataProvider data_refused; |
| 11592 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11593 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11594 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11596 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11597 | session->http_server_properties(); |
| 11598 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11599 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11600 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11601 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11602 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11603 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11604 | alternative_service_info_vector.push_back( |
| 11605 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11606 | alternative_service1, expiration, |
| 11607 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11608 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11609 | alternative_service_info_vector.push_back( |
| 11610 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11611 | alternative_service2, expiration, |
| 11612 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11613 | |
| 11614 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11615 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11616 | |
| 11617 | // Mark one of the QUIC alternative service as broken. |
| 11618 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11619 | EXPECT_EQ(2u, |
| 11620 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11621 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11622 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11623 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11624 | request.method = "GET"; |
| 11625 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11626 | request.traffic_annotation = |
| 11627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11628 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11629 | TestCompletionCallback callback; |
| 11630 | NetErrorDetails details; |
| 11631 | EXPECT_FALSE(details.quic_broken); |
| 11632 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11633 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11634 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11635 | EXPECT_FALSE(details.quic_broken); |
| 11636 | } |
| 11637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11638 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11639 | HttpRequestInfo request; |
| 11640 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11641 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11642 | request.traffic_annotation = |
| 11643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11644 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11645 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11646 | StaticSocketDataProvider first_data; |
| 11647 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11648 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11649 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11650 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11652 | |
| 11653 | MockRead data_reads[] = { |
| 11654 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11655 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11656 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11657 | }; |
| 11658 | StaticSocketDataProvider second_data( |
| 11659 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11660 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11663 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11664 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11665 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11666 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11667 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11668 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11669 | // Port is ignored by MockConnect anyway. |
| 11670 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11671 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11672 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11673 | http_server_properties->SetHttp2AlternativeService( |
| 11674 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11677 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11679 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11681 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11683 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11684 | ASSERT_TRUE(response); |
| 11685 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11686 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11687 | |
| 11688 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11689 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11690 | EXPECT_EQ("hello world", response_data); |
| 11691 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11692 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11693 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11694 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11695 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11696 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11697 | EXPECT_TRUE( |
| 11698 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11699 | } |
| 11700 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11701 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11702 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11703 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11704 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11705 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11706 | HttpRequestInfo restricted_port_request; |
| 11707 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11708 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11709 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11710 | restricted_port_request.traffic_annotation = |
| 11711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11712 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11713 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11714 | StaticSocketDataProvider first_data; |
| 11715 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11716 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11717 | |
| 11718 | MockRead data_reads[] = { |
| 11719 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11720 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11721 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11722 | }; |
| 11723 | StaticSocketDataProvider second_data( |
| 11724 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11725 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11726 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11727 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11729 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11730 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11731 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11732 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11733 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11734 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11735 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11736 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11737 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11738 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11739 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11740 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11742 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11743 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11744 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11745 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11746 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11748 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11749 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11750 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11751 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11752 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11753 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11754 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11755 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11756 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11757 | |
| 11758 | HttpRequestInfo restricted_port_request; |
| 11759 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11760 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11761 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11762 | restricted_port_request.traffic_annotation = |
| 11763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11764 | |
| 11765 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11766 | StaticSocketDataProvider first_data; |
| 11767 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11768 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11769 | |
| 11770 | MockRead data_reads[] = { |
| 11771 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11772 | MockRead("hello world"), |
| 11773 | MockRead(ASYNC, OK), |
| 11774 | }; |
| 11775 | StaticSocketDataProvider second_data( |
| 11776 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11777 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11778 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11779 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11780 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11783 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11784 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11785 | session->http_server_properties(); |
| 11786 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11787 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11788 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11789 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11790 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11791 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11792 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11795 | TestCompletionCallback callback; |
| 11796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11797 | EXPECT_EQ(ERR_IO_PENDING, |
| 11798 | trans.Start(&restricted_port_request, callback.callback(), |
| 11799 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11800 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11801 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11802 | } |
| 11803 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11804 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11805 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11806 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11807 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11808 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11809 | HttpRequestInfo restricted_port_request; |
| 11810 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11811 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11812 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11813 | restricted_port_request.traffic_annotation = |
| 11814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11815 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11816 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11817 | StaticSocketDataProvider first_data; |
| 11818 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11819 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11820 | |
| 11821 | MockRead data_reads[] = { |
| 11822 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11823 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11824 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11825 | }; |
| 11826 | StaticSocketDataProvider second_data( |
| 11827 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11828 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11829 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11830 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11834 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11835 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11836 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11837 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11838 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11839 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11840 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11841 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11842 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11843 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11846 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11847 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11848 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11849 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11851 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11852 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11853 | } |
| 11854 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11855 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11856 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11857 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11858 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11859 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11860 | HttpRequestInfo unrestricted_port_request; |
| 11861 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11862 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11863 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11864 | unrestricted_port_request.traffic_annotation = |
| 11865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11866 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11867 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11868 | StaticSocketDataProvider first_data; |
| 11869 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11870 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11871 | |
| 11872 | MockRead data_reads[] = { |
| 11873 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11874 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11875 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11876 | }; |
| 11877 | StaticSocketDataProvider second_data( |
| 11878 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11879 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11880 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11881 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11885 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11886 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11887 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11888 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11889 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11890 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11891 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11892 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11893 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11894 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11897 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11898 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11899 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11900 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11902 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11903 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11904 | } |
| 11905 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11906 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11907 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11908 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11909 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11910 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11911 | HttpRequestInfo unrestricted_port_request; |
| 11912 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11913 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11914 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11915 | unrestricted_port_request.traffic_annotation = |
| 11916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11917 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11918 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11919 | StaticSocketDataProvider first_data; |
| 11920 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11921 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11922 | |
| 11923 | MockRead data_reads[] = { |
| 11924 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11925 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11926 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11927 | }; |
| 11928 | StaticSocketDataProvider second_data( |
| 11929 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11930 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11931 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11932 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11934 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11936 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11937 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11938 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11939 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11940 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11941 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11942 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11943 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11944 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11945 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11947 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11948 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11950 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11951 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11953 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11954 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11955 | } |
| 11956 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11957 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11958 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11959 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11960 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11961 | HttpRequestInfo request; |
| 11962 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11963 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11964 | request.traffic_annotation = |
| 11965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11966 | |
| 11967 | // The alternate protocol request will error out before we attempt to connect, |
| 11968 | // so only the standard HTTP request will try to connect. |
| 11969 | MockRead data_reads[] = { |
| 11970 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11971 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11972 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11973 | }; |
| 11974 | StaticSocketDataProvider data( |
| 11975 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11976 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11979 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11980 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11981 | session->http_server_properties(); |
| 11982 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11983 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11984 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11985 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11986 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11987 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11990 | TestCompletionCallback callback; |
| 11991 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11992 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11993 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11994 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11995 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11997 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11998 | ASSERT_TRUE(response); |
| 11999 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12000 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12001 | |
| 12002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12003 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12004 | EXPECT_EQ("hello world", response_data); |
| 12005 | } |
| 12006 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12007 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12008 | HttpRequestInfo request; |
| 12009 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12010 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12011 | request.traffic_annotation = |
| 12012 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12013 | |
| 12014 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12015 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12016 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12017 | MockRead("\r\n"), |
| 12018 | MockRead("hello world"), |
| 12019 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12020 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12021 | |
| 12022 | StaticSocketDataProvider first_transaction( |
| 12023 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12024 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12025 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12026 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12027 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12028 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12029 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12030 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12031 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12032 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12033 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12034 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12035 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12036 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12037 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12038 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12039 | }; |
| 12040 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12041 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12042 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12043 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12044 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12045 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12046 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12047 | NULL, 0, NULL, 0); |
| 12048 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12049 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12050 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12051 | &hanging_non_alternate_protocol_socket); |
| 12052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12053 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12056 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12057 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12058 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12059 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12061 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12062 | |
| 12063 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12064 | ASSERT_TRUE(response); |
| 12065 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12066 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12067 | |
| 12068 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12069 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12070 | EXPECT_EQ("hello world", response_data); |
| 12071 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12072 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12073 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12075 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12077 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12078 | |
| 12079 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12080 | ASSERT_TRUE(response); |
| 12081 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12082 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12083 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12084 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12085 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12086 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12087 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12088 | } |
| 12089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12090 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12091 | HttpRequestInfo request; |
| 12092 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12093 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12094 | request.traffic_annotation = |
| 12095 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12096 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12097 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12098 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12099 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12100 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12101 | MockRead("\r\n"), |
| 12102 | MockRead("hello world"), |
| 12103 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12104 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12105 | }; |
| 12106 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12107 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 12108 | 0); |
| 12109 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12110 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12111 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12112 | ssl_http11.ssl_info.cert = |
| 12113 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12114 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12116 | |
| 12117 | // Second transaction starts an alternative and a non-alternative Job. |
| 12118 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12119 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12120 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 12121 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12122 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12123 | |
| 12124 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 12125 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12126 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12127 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12128 | // Third transaction starts an alternative and a non-alternative job. |
| 12129 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12130 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12131 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12132 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12133 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12134 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12135 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12136 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12137 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12138 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12139 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12140 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12141 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12142 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12143 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12144 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12145 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12146 | }; |
| 12147 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12148 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12149 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12150 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12151 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12152 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12153 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12154 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 12155 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12156 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12159 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12160 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12161 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12162 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12164 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12165 | |
| 12166 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12167 | ASSERT_TRUE(response); |
| 12168 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12169 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12170 | |
| 12171 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12172 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12173 | EXPECT_EQ("hello world", response_data); |
| 12174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12175 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12176 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12177 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12180 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12181 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12182 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12183 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12184 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12185 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12186 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12187 | |
| 12188 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12189 | ASSERT_TRUE(response); |
| 12190 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12191 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12192 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12193 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12194 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12195 | EXPECT_EQ("hello!", response_data); |
| 12196 | |
| 12197 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12198 | ASSERT_TRUE(response); |
| 12199 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12200 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12201 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12202 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12203 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12204 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12205 | } |
| 12206 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12207 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12208 | HttpRequestInfo request; |
| 12209 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12210 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12211 | request.traffic_annotation = |
| 12212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12213 | |
| 12214 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12215 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12216 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12217 | MockRead("\r\n"), |
| 12218 | MockRead("hello world"), |
| 12219 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12220 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12221 | }; |
| 12222 | |
| 12223 | StaticSocketDataProvider first_transaction( |
| 12224 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12225 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12226 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12227 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12228 | ssl.ssl_info.cert = |
| 12229 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12230 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12231 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12232 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12233 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12234 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 12235 | NULL, 0, NULL, 0); |
| 12236 | hanging_alternate_protocol_socket.set_connect_data( |
| 12237 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12238 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12239 | &hanging_alternate_protocol_socket); |
| 12240 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12241 | // 2nd request is just a copy of the first one, over HTTP/1.1 again. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12242 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 12243 | NULL, 0); |
| 12244 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12247 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12250 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12251 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12253 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12255 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12256 | |
| 12257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12258 | ASSERT_TRUE(response); |
| 12259 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12260 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12261 | |
| 12262 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12263 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12264 | EXPECT_EQ("hello world", response_data); |
| 12265 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12266 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12267 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12268 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12269 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12271 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12272 | |
| 12273 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12274 | ASSERT_TRUE(response); |
| 12275 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12276 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12277 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12278 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12279 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12280 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12281 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12282 | } |
| 12283 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12284 | class CapturingProxyResolver : public ProxyResolver { |
| 12285 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12286 | CapturingProxyResolver() = default; |
| 12287 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12288 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12289 | int GetProxyForURL(const GURL& url, |
| 12290 | ProxyInfo* results, |
| 12291 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12292 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12293 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12294 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12295 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12296 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12297 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12298 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12299 | } |
| 12300 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12301 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12302 | |
| 12303 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12304 | std::vector<GURL> resolved_; |
| 12305 | |
| 12306 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12307 | }; |
| 12308 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12309 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12310 | public: |
| 12311 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12312 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12313 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12314 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12315 | std::unique_ptr<ProxyResolver>* resolver, |
| 12316 | const net::CompletionCallback& callback, |
| 12317 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12318 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12319 | return OK; |
| 12320 | } |
| 12321 | |
| 12322 | private: |
| 12323 | ProxyResolver* resolver_; |
| 12324 | }; |
| 12325 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12326 | // Test that proxy is resolved using the origin url, |
| 12327 | // regardless of the alternative server. |
| 12328 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12329 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12330 | ProxyConfig proxy_config; |
| 12331 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12332 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12333 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12334 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12335 | |
| 12336 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12337 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12338 | &capturing_proxy_resolver); |
| 12339 | |
| 12340 | TestNetLog net_log; |
| 12341 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12342 | session_deps_.proxy_resolution_service = |
| 12343 | std::make_unique<ProxyResolutionService>( |
| 12344 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12345 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12346 | |
| 12347 | session_deps_.net_log = &net_log; |
| 12348 | |
| 12349 | // Configure alternative service with a hostname that is not bypassed by the |
| 12350 | // proxy. |
| 12351 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12352 | HttpServerProperties* http_server_properties = |
| 12353 | session->http_server_properties(); |
| 12354 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12355 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12356 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12357 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12358 | http_server_properties->SetHttp2AlternativeService( |
| 12359 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12360 | |
| 12361 | // Non-alternative job should hang. |
| 12362 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 12363 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 12364 | nullptr, 0); |
| 12365 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12366 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12367 | &hanging_alternate_protocol_socket); |
| 12368 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12369 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12370 | |
| 12371 | HttpRequestInfo request; |
| 12372 | request.method = "GET"; |
| 12373 | request.url = GURL("https://www.example.org/"); |
| 12374 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12375 | request.traffic_annotation = |
| 12376 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12377 | |
| 12378 | SpdySerializedFrame req( |
| 12379 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12380 | |
| 12381 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12382 | |
| 12383 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12384 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12385 | MockRead spdy_reads[] = { |
| 12386 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12387 | }; |
| 12388 | |
| 12389 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12390 | arraysize(spdy_writes)); |
| 12391 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12392 | |
| 12393 | TestCompletionCallback callback; |
| 12394 | |
| 12395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12396 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12397 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12398 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12399 | |
| 12400 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12401 | ASSERT_TRUE(response); |
| 12402 | ASSERT_TRUE(response->headers); |
| 12403 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12404 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12405 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12406 | |
| 12407 | std::string response_data; |
| 12408 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12409 | EXPECT_EQ("hello!", response_data); |
| 12410 | |
| 12411 | // Origin host bypasses proxy, no resolution should have happened. |
| 12412 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12413 | } |
| 12414 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12415 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12416 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12417 | proxy_config.set_auto_detect(true); |
| 12418 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12419 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12420 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12421 | session_deps_.proxy_resolution_service = |
| 12422 | std::make_unique<ProxyResolutionService>( |
| 12423 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12424 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12425 | std::make_unique<CapturingProxyResolverFactory>( |
| 12426 | &capturing_proxy_resolver), |
| 12427 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12428 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12429 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12430 | |
| 12431 | HttpRequestInfo request; |
| 12432 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12433 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12434 | request.traffic_annotation = |
| 12435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12436 | |
| 12437 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12438 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12439 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12440 | MockRead("\r\n"), |
| 12441 | MockRead("hello world"), |
| 12442 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12443 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12444 | }; |
| 12445 | |
| 12446 | StaticSocketDataProvider first_transaction( |
| 12447 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12448 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12449 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12450 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12451 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12452 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12453 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12454 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12455 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12456 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12457 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12458 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12459 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12460 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12462 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12463 | }; |
| 12464 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12465 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12466 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12467 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12468 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12469 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12470 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12471 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12472 | }; |
| 12473 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12474 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12475 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12476 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12477 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12478 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12479 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12480 | NULL, 0, NULL, 0); |
| 12481 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12482 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12483 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12484 | &hanging_non_alternate_protocol_socket); |
| 12485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12486 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12489 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12490 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12491 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12492 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12494 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12495 | |
| 12496 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12497 | ASSERT_TRUE(response); |
| 12498 | ASSERT_TRUE(response->headers); |
| 12499 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12500 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12501 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12502 | |
| 12503 | std::string response_data; |
| 12504 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12505 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12506 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12507 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12508 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12509 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12510 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12511 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12512 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12513 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12514 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12515 | ASSERT_TRUE(response); |
| 12516 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12517 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12518 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12519 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12520 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12521 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12522 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12523 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12524 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12525 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12526 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12527 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12528 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12529 | LoadTimingInfo load_timing_info; |
| 12530 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12531 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12532 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12533 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12534 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12535 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12536 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12537 | HttpRequestInfo request; |
| 12538 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12539 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12540 | request.traffic_annotation = |
| 12541 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12542 | |
| 12543 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12544 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12545 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12546 | MockRead("\r\n"), |
| 12547 | MockRead("hello world"), |
| 12548 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12549 | }; |
| 12550 | |
| 12551 | StaticSocketDataProvider first_transaction( |
| 12552 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12553 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12554 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12555 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12557 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12558 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12559 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12560 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12561 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12562 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12563 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12564 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12565 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12566 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12567 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12568 | }; |
| 12569 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12570 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12571 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12572 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12573 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12574 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12577 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12578 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12579 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12580 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12581 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12583 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12584 | |
| 12585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12586 | ASSERT_TRUE(response); |
| 12587 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12588 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12589 | |
| 12590 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12591 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12592 | EXPECT_EQ("hello world", response_data); |
| 12593 | |
| 12594 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12595 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12596 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12597 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12598 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12599 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12600 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12601 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12602 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12604 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12606 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12607 | |
| 12608 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12609 | ASSERT_TRUE(response); |
| 12610 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12611 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12612 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12613 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12614 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12615 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12616 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12617 | } |
| 12618 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12619 | // GenerateAuthToken is a mighty big test. |
| 12620 | // It tests all permutation of GenerateAuthToken behavior: |
| 12621 | // - Synchronous and Asynchronous completion. |
| 12622 | // - OK or error on completion. |
| 12623 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12624 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12625 | // - Non-authenticating and authenticating backend. |
| 12626 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12627 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12628 | // problems generating an auth token for an authenticating proxy, we don't |
| 12629 | // need to test all permutations of the backend server). |
| 12630 | // |
| 12631 | // The test proceeds by going over each of the configuration cases, and |
| 12632 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12633 | // specifies both the configuration for the test as well as the expectations |
| 12634 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12635 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12636 | static const char kServer[] = "http://www.example.com"; |
| 12637 | static const char kSecureServer[] = "https://www.example.com"; |
| 12638 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12639 | |
| 12640 | enum AuthTiming { |
| 12641 | AUTH_NONE, |
| 12642 | AUTH_SYNC, |
| 12643 | AUTH_ASYNC, |
| 12644 | }; |
| 12645 | |
| 12646 | const MockWrite kGet( |
| 12647 | "GET / HTTP/1.1\r\n" |
| 12648 | "Host: www.example.com\r\n" |
| 12649 | "Connection: keep-alive\r\n\r\n"); |
| 12650 | const MockWrite kGetProxy( |
| 12651 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12652 | "Host: www.example.com\r\n" |
| 12653 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12654 | const MockWrite kGetAuth( |
| 12655 | "GET / HTTP/1.1\r\n" |
| 12656 | "Host: www.example.com\r\n" |
| 12657 | "Connection: keep-alive\r\n" |
| 12658 | "Authorization: auth_token\r\n\r\n"); |
| 12659 | const MockWrite kGetProxyAuth( |
| 12660 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12661 | "Host: www.example.com\r\n" |
| 12662 | "Proxy-Connection: keep-alive\r\n" |
| 12663 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12664 | const MockWrite kGetAuthThroughProxy( |
| 12665 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12666 | "Host: www.example.com\r\n" |
| 12667 | "Proxy-Connection: keep-alive\r\n" |
| 12668 | "Authorization: auth_token\r\n\r\n"); |
| 12669 | const MockWrite kGetAuthWithProxyAuth( |
| 12670 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12671 | "Host: www.example.com\r\n" |
| 12672 | "Proxy-Connection: keep-alive\r\n" |
| 12673 | "Proxy-Authorization: auth_token\r\n" |
| 12674 | "Authorization: auth_token\r\n\r\n"); |
| 12675 | const MockWrite kConnect( |
| 12676 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12677 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12678 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12679 | const MockWrite kConnectProxyAuth( |
| 12680 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12681 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12682 | "Proxy-Connection: keep-alive\r\n" |
| 12683 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12684 | |
| 12685 | const MockRead kSuccess( |
| 12686 | "HTTP/1.1 200 OK\r\n" |
| 12687 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12688 | "Content-Length: 3\r\n\r\n" |
| 12689 | "Yes"); |
| 12690 | const MockRead kFailure( |
| 12691 | "Should not be called."); |
| 12692 | const MockRead kServerChallenge( |
| 12693 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12694 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12695 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12696 | "Content-Length: 14\r\n\r\n" |
| 12697 | "Unauthorized\r\n"); |
| 12698 | const MockRead kProxyChallenge( |
| 12699 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12700 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12701 | "Proxy-Connection: close\r\n" |
| 12702 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12703 | "Content-Length: 14\r\n\r\n" |
| 12704 | "Unauthorized\r\n"); |
| 12705 | const MockRead kProxyConnected( |
| 12706 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12707 | |
| 12708 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12709 | // no constructors, but the C++ compiler on Windows warns about |
| 12710 | // unspecified data in compound literals. So, moved to using constructors, |
| 12711 | // and TestRound's created with the default constructor should not be used. |
| 12712 | struct TestRound { |
| 12713 | TestRound() |
| 12714 | : expected_rv(ERR_UNEXPECTED), |
| 12715 | extra_write(NULL), |
| 12716 | extra_read(NULL) { |
| 12717 | } |
| 12718 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12719 | int expected_rv_arg) |
| 12720 | : write(write_arg), |
| 12721 | read(read_arg), |
| 12722 | expected_rv(expected_rv_arg), |
| 12723 | extra_write(NULL), |
| 12724 | extra_read(NULL) { |
| 12725 | } |
| 12726 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12727 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12728 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12729 | : write(write_arg), |
| 12730 | read(read_arg), |
| 12731 | expected_rv(expected_rv_arg), |
| 12732 | extra_write(extra_write_arg), |
| 12733 | extra_read(extra_read_arg) { |
| 12734 | } |
| 12735 | MockWrite write; |
| 12736 | MockRead read; |
| 12737 | int expected_rv; |
| 12738 | const MockWrite* extra_write; |
| 12739 | const MockRead* extra_read; |
| 12740 | }; |
| 12741 | |
| 12742 | static const int kNoSSL = 500; |
| 12743 | |
| 12744 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12745 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12746 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12747 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12748 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12749 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12750 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12751 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12752 | int num_auth_rounds; |
| 12753 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12754 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12755 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12756 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12757 | {__LINE__, |
| 12758 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12759 | AUTH_NONE, |
| 12760 | OK, |
| 12761 | kServer, |
| 12762 | AUTH_NONE, |
| 12763 | OK, |
| 12764 | 1, |
| 12765 | kNoSSL, |
| 12766 | {TestRound(kGet, kSuccess, OK)}}, |
| 12767 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12768 | {__LINE__, |
| 12769 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12770 | AUTH_NONE, |
| 12771 | OK, |
| 12772 | kServer, |
| 12773 | AUTH_SYNC, |
| 12774 | OK, |
| 12775 | 2, |
| 12776 | kNoSSL, |
| 12777 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12778 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12779 | {__LINE__, |
| 12780 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12781 | AUTH_NONE, |
| 12782 | OK, |
| 12783 | kServer, |
| 12784 | AUTH_SYNC, |
| 12785 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12786 | 3, |
| 12787 | kNoSSL, |
| 12788 | {TestRound(kGet, kServerChallenge, OK), |
| 12789 | TestRound(kGet, kServerChallenge, OK), |
| 12790 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12791 | {__LINE__, |
| 12792 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12793 | AUTH_NONE, |
| 12794 | OK, |
| 12795 | kServer, |
| 12796 | AUTH_SYNC, |
| 12797 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12798 | 2, |
| 12799 | kNoSSL, |
| 12800 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12801 | {__LINE__, |
| 12802 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12803 | AUTH_NONE, |
| 12804 | OK, |
| 12805 | kServer, |
| 12806 | AUTH_SYNC, |
| 12807 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12808 | 2, |
| 12809 | kNoSSL, |
| 12810 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12811 | {__LINE__, |
| 12812 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12813 | AUTH_SYNC, |
| 12814 | ERR_FAILED, |
| 12815 | kServer, |
| 12816 | AUTH_NONE, |
| 12817 | OK, |
| 12818 | 2, |
| 12819 | kNoSSL, |
| 12820 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12821 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12822 | {__LINE__, |
| 12823 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12824 | AUTH_ASYNC, |
| 12825 | ERR_FAILED, |
| 12826 | kServer, |
| 12827 | AUTH_NONE, |
| 12828 | OK, |
| 12829 | 2, |
| 12830 | kNoSSL, |
| 12831 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12832 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12833 | {__LINE__, |
| 12834 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12835 | AUTH_NONE, |
| 12836 | OK, |
| 12837 | kServer, |
| 12838 | AUTH_SYNC, |
| 12839 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12840 | 2, |
| 12841 | kNoSSL, |
| 12842 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12843 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12844 | {__LINE__, |
| 12845 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12846 | AUTH_NONE, |
| 12847 | OK, |
| 12848 | kServer, |
| 12849 | AUTH_ASYNC, |
| 12850 | ERR_FAILED, |
| 12851 | 2, |
| 12852 | kNoSSL, |
| 12853 | {TestRound(kGet, kServerChallenge, OK), |
| 12854 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12855 | {__LINE__, |
| 12856 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12857 | AUTH_NONE, |
| 12858 | OK, |
| 12859 | kServer, |
| 12860 | AUTH_ASYNC, |
| 12861 | OK, |
| 12862 | 2, |
| 12863 | kNoSSL, |
| 12864 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12865 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12866 | {__LINE__, |
| 12867 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12868 | AUTH_NONE, |
| 12869 | OK, |
| 12870 | kServer, |
| 12871 | AUTH_ASYNC, |
| 12872 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12873 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12874 | kNoSSL, |
| 12875 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12876 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12877 | TestRound(kGet, kServerChallenge, OK), |
| 12878 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12879 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12880 | {__LINE__, |
| 12881 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12882 | AUTH_NONE, |
| 12883 | OK, |
| 12884 | kServer, |
| 12885 | AUTH_NONE, |
| 12886 | OK, |
| 12887 | 1, |
| 12888 | kNoSSL, |
| 12889 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12890 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12891 | {__LINE__, |
| 12892 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12893 | AUTH_NONE, |
| 12894 | OK, |
| 12895 | kServer, |
| 12896 | AUTH_SYNC, |
| 12897 | OK, |
| 12898 | 2, |
| 12899 | kNoSSL, |
| 12900 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12901 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12902 | {__LINE__, |
| 12903 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12904 | AUTH_NONE, |
| 12905 | OK, |
| 12906 | kServer, |
| 12907 | AUTH_SYNC, |
| 12908 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12909 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12910 | kNoSSL, |
| 12911 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12912 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12913 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12914 | {__LINE__, |
| 12915 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12916 | AUTH_NONE, |
| 12917 | OK, |
| 12918 | kServer, |
| 12919 | AUTH_ASYNC, |
| 12920 | OK, |
| 12921 | 2, |
| 12922 | kNoSSL, |
| 12923 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12924 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12925 | {__LINE__, |
| 12926 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12927 | AUTH_NONE, |
| 12928 | OK, |
| 12929 | kServer, |
| 12930 | AUTH_ASYNC, |
| 12931 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12932 | 2, |
| 12933 | kNoSSL, |
| 12934 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12935 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12936 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12937 | {__LINE__, |
| 12938 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12939 | AUTH_SYNC, |
| 12940 | OK, |
| 12941 | kServer, |
| 12942 | AUTH_NONE, |
| 12943 | OK, |
| 12944 | 2, |
| 12945 | kNoSSL, |
| 12946 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12947 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12948 | {__LINE__, |
| 12949 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12950 | AUTH_SYNC, |
| 12951 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12952 | kServer, |
| 12953 | AUTH_NONE, |
| 12954 | OK, |
| 12955 | 2, |
| 12956 | kNoSSL, |
| 12957 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12958 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12959 | {__LINE__, |
| 12960 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12961 | AUTH_ASYNC, |
| 12962 | OK, |
| 12963 | kServer, |
| 12964 | AUTH_NONE, |
| 12965 | OK, |
| 12966 | 2, |
| 12967 | kNoSSL, |
| 12968 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12969 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12970 | {__LINE__, |
| 12971 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12972 | AUTH_ASYNC, |
| 12973 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12974 | kServer, |
| 12975 | AUTH_NONE, |
| 12976 | OK, |
| 12977 | 2, |
| 12978 | kNoSSL, |
| 12979 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12980 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12981 | {__LINE__, |
| 12982 | kProxy, |
| 12983 | AUTH_ASYNC, |
| 12984 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12985 | kServer, |
| 12986 | AUTH_NONE, |
| 12987 | OK, |
| 12988 | 3, |
| 12989 | kNoSSL, |
| 12990 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12991 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12992 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12993 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12994 | {__LINE__, |
| 12995 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12996 | AUTH_SYNC, |
| 12997 | OK, |
| 12998 | kServer, |
| 12999 | AUTH_SYNC, |
| 13000 | OK, |
| 13001 | 3, |
| 13002 | kNoSSL, |
| 13003 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13004 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13005 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13006 | {__LINE__, |
| 13007 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13008 | AUTH_SYNC, |
| 13009 | OK, |
| 13010 | kServer, |
| 13011 | AUTH_SYNC, |
| 13012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13013 | 3, |
| 13014 | kNoSSL, |
| 13015 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13016 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13017 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13018 | {__LINE__, |
| 13019 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13020 | AUTH_ASYNC, |
| 13021 | OK, |
| 13022 | kServer, |
| 13023 | AUTH_SYNC, |
| 13024 | OK, |
| 13025 | 3, |
| 13026 | kNoSSL, |
| 13027 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13028 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13029 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13030 | {__LINE__, |
| 13031 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13032 | AUTH_ASYNC, |
| 13033 | OK, |
| 13034 | kServer, |
| 13035 | AUTH_SYNC, |
| 13036 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13037 | 3, |
| 13038 | kNoSSL, |
| 13039 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13040 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13041 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13042 | {__LINE__, |
| 13043 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13044 | AUTH_SYNC, |
| 13045 | OK, |
| 13046 | kServer, |
| 13047 | AUTH_ASYNC, |
| 13048 | OK, |
| 13049 | 3, |
| 13050 | kNoSSL, |
| 13051 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13052 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13053 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13054 | {__LINE__, |
| 13055 | kProxy, |
| 13056 | AUTH_SYNC, |
| 13057 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13058 | kServer, |
| 13059 | AUTH_ASYNC, |
| 13060 | OK, |
| 13061 | 4, |
| 13062 | kNoSSL, |
| 13063 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13064 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13065 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13066 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13067 | {__LINE__, |
| 13068 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13069 | AUTH_SYNC, |
| 13070 | OK, |
| 13071 | kServer, |
| 13072 | AUTH_ASYNC, |
| 13073 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13074 | 3, |
| 13075 | kNoSSL, |
| 13076 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13077 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13078 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 13082 | OK, |
| 13083 | kServer, |
| 13084 | AUTH_ASYNC, |
| 13085 | OK, |
| 13086 | 3, |
| 13087 | kNoSSL, |
| 13088 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13089 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13090 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13091 | {__LINE__, |
| 13092 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13093 | AUTH_ASYNC, |
| 13094 | OK, |
| 13095 | kServer, |
| 13096 | AUTH_ASYNC, |
| 13097 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13098 | 3, |
| 13099 | kNoSSL, |
| 13100 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13101 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13102 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13103 | {__LINE__, |
| 13104 | kProxy, |
| 13105 | AUTH_ASYNC, |
| 13106 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13107 | kServer, |
| 13108 | AUTH_ASYNC, |
| 13109 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13110 | 4, |
| 13111 | kNoSSL, |
| 13112 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13113 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13114 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13115 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13116 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13117 | {__LINE__, |
| 13118 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13119 | AUTH_NONE, |
| 13120 | OK, |
| 13121 | kSecureServer, |
| 13122 | AUTH_NONE, |
| 13123 | OK, |
| 13124 | 1, |
| 13125 | 0, |
| 13126 | {TestRound(kGet, kSuccess, OK)}}, |
| 13127 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13128 | {__LINE__, |
| 13129 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13130 | AUTH_NONE, |
| 13131 | OK, |
| 13132 | kSecureServer, |
| 13133 | AUTH_SYNC, |
| 13134 | OK, |
| 13135 | 2, |
| 13136 | 0, |
| 13137 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13138 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13139 | {__LINE__, |
| 13140 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13141 | AUTH_NONE, |
| 13142 | OK, |
| 13143 | kSecureServer, |
| 13144 | AUTH_SYNC, |
| 13145 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13146 | 2, |
| 13147 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13148 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13149 | {__LINE__, |
| 13150 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13151 | AUTH_NONE, |
| 13152 | OK, |
| 13153 | kSecureServer, |
| 13154 | AUTH_ASYNC, |
| 13155 | OK, |
| 13156 | 2, |
| 13157 | 0, |
| 13158 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13159 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13160 | {__LINE__, |
| 13161 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13162 | AUTH_NONE, |
| 13163 | OK, |
| 13164 | kSecureServer, |
| 13165 | AUTH_ASYNC, |
| 13166 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13167 | 2, |
| 13168 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13169 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13170 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13171 | {__LINE__, |
| 13172 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13173 | AUTH_NONE, |
| 13174 | OK, |
| 13175 | kSecureServer, |
| 13176 | AUTH_NONE, |
| 13177 | OK, |
| 13178 | 1, |
| 13179 | 0, |
| 13180 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13181 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13182 | {__LINE__, |
| 13183 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13184 | AUTH_NONE, |
| 13185 | OK, |
| 13186 | kSecureServer, |
| 13187 | AUTH_SYNC, |
| 13188 | OK, |
| 13189 | 2, |
| 13190 | 0, |
| 13191 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13192 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13193 | {__LINE__, |
| 13194 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13195 | AUTH_NONE, |
| 13196 | OK, |
| 13197 | kSecureServer, |
| 13198 | AUTH_SYNC, |
| 13199 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13200 | 2, |
| 13201 | 0, |
| 13202 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13203 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13204 | {__LINE__, |
| 13205 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13206 | AUTH_NONE, |
| 13207 | OK, |
| 13208 | kSecureServer, |
| 13209 | AUTH_ASYNC, |
| 13210 | OK, |
| 13211 | 2, |
| 13212 | 0, |
| 13213 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13214 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13215 | {__LINE__, |
| 13216 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13217 | AUTH_NONE, |
| 13218 | OK, |
| 13219 | kSecureServer, |
| 13220 | AUTH_ASYNC, |
| 13221 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13222 | 2, |
| 13223 | 0, |
| 13224 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13225 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13226 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13227 | {__LINE__, |
| 13228 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13229 | AUTH_SYNC, |
| 13230 | OK, |
| 13231 | kSecureServer, |
| 13232 | AUTH_NONE, |
| 13233 | OK, |
| 13234 | 2, |
| 13235 | 1, |
| 13236 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13237 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13238 | {__LINE__, |
| 13239 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13240 | AUTH_SYNC, |
| 13241 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13242 | kSecureServer, |
| 13243 | AUTH_NONE, |
| 13244 | OK, |
| 13245 | 2, |
| 13246 | kNoSSL, |
| 13247 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13248 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13249 | {__LINE__, |
| 13250 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13251 | AUTH_SYNC, |
| 13252 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13253 | kSecureServer, |
| 13254 | AUTH_NONE, |
| 13255 | OK, |
| 13256 | 2, |
| 13257 | kNoSSL, |
| 13258 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13259 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13260 | {__LINE__, |
| 13261 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13262 | AUTH_SYNC, |
| 13263 | ERR_UNEXPECTED, |
| 13264 | kSecureServer, |
| 13265 | AUTH_NONE, |
| 13266 | OK, |
| 13267 | 2, |
| 13268 | kNoSSL, |
| 13269 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13270 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13271 | {__LINE__, |
| 13272 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13273 | AUTH_ASYNC, |
| 13274 | OK, |
| 13275 | kSecureServer, |
| 13276 | AUTH_NONE, |
| 13277 | OK, |
| 13278 | 2, |
| 13279 | 1, |
| 13280 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13281 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13282 | {__LINE__, |
| 13283 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13284 | AUTH_ASYNC, |
| 13285 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13286 | kSecureServer, |
| 13287 | AUTH_NONE, |
| 13288 | OK, |
| 13289 | 2, |
| 13290 | kNoSSL, |
| 13291 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13292 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13293 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13294 | {__LINE__, |
| 13295 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13296 | AUTH_SYNC, |
| 13297 | OK, |
| 13298 | kSecureServer, |
| 13299 | AUTH_SYNC, |
| 13300 | OK, |
| 13301 | 3, |
| 13302 | 1, |
| 13303 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13304 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13305 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13306 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13307 | {__LINE__, |
| 13308 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13309 | AUTH_SYNC, |
| 13310 | OK, |
| 13311 | kSecureServer, |
| 13312 | AUTH_SYNC, |
| 13313 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13314 | 3, |
| 13315 | 1, |
| 13316 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13317 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13318 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13319 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13320 | {__LINE__, |
| 13321 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13322 | AUTH_ASYNC, |
| 13323 | OK, |
| 13324 | kSecureServer, |
| 13325 | AUTH_SYNC, |
| 13326 | OK, |
| 13327 | 3, |
| 13328 | 1, |
| 13329 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13330 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13331 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13332 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13333 | {__LINE__, |
| 13334 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13335 | AUTH_ASYNC, |
| 13336 | OK, |
| 13337 | kSecureServer, |
| 13338 | AUTH_SYNC, |
| 13339 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13340 | 3, |
| 13341 | 1, |
| 13342 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13343 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13344 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13345 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13346 | {__LINE__, |
| 13347 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13348 | AUTH_SYNC, |
| 13349 | OK, |
| 13350 | kSecureServer, |
| 13351 | AUTH_ASYNC, |
| 13352 | OK, |
| 13353 | 3, |
| 13354 | 1, |
| 13355 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13356 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13357 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13358 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13359 | {__LINE__, |
| 13360 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13361 | AUTH_SYNC, |
| 13362 | OK, |
| 13363 | kSecureServer, |
| 13364 | AUTH_ASYNC, |
| 13365 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13366 | 3, |
| 13367 | 1, |
| 13368 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13369 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13370 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13371 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13372 | {__LINE__, |
| 13373 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13374 | AUTH_ASYNC, |
| 13375 | OK, |
| 13376 | kSecureServer, |
| 13377 | AUTH_ASYNC, |
| 13378 | OK, |
| 13379 | 3, |
| 13380 | 1, |
| 13381 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13382 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13383 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13384 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13385 | {__LINE__, |
| 13386 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13387 | AUTH_ASYNC, |
| 13388 | OK, |
| 13389 | kSecureServer, |
| 13390 | AUTH_ASYNC, |
| 13391 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13392 | 3, |
| 13393 | 1, |
| 13394 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13395 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13396 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13397 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13398 | {__LINE__, |
| 13399 | kProxy, |
| 13400 | AUTH_ASYNC, |
| 13401 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13402 | kSecureServer, |
| 13403 | AUTH_ASYNC, |
| 13404 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13405 | 4, |
| 13406 | 2, |
| 13407 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13408 | TestRound(kConnect, kProxyChallenge, OK), |
| 13409 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13410 | &kServerChallenge), |
| 13411 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13412 | }; |
| 13413 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13414 | for (const auto& test_config : test_configs) { |
| 13415 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13416 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13417 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13418 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13419 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13420 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13421 | |
| 13422 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13423 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13424 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13425 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13426 | std::string auth_challenge = "Mock realm=proxy"; |
| 13427 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13428 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13429 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13430 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13431 | empty_ssl_info, origin, |
| 13432 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13433 | auth_handler->SetGenerateExpectation( |
| 13434 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13435 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13436 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13437 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13438 | } |
| 13439 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13440 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13441 | std::string auth_challenge = "Mock realm=server"; |
| 13442 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13443 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13444 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13445 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13446 | empty_ssl_info, origin, |
| 13447 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13448 | auth_handler->SetGenerateExpectation( |
| 13449 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13450 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13451 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13452 | |
| 13453 | // The second handler always succeeds. It should only be used where there |
| 13454 | // are multiple auth sessions for server auth in the same network |
| 13455 | // transaction using the same auth scheme. |
| 13456 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13457 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13458 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13459 | empty_ssl_info, origin, |
| 13460 | NetLogWithSource()); |
| 13461 | second_handler->SetGenerateExpectation(true, OK); |
| 13462 | auth_factory->AddMockHandler(second_handler.release(), |
| 13463 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13464 | } |
| 13465 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13466 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13467 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13468 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13469 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13470 | session_deps_.proxy_resolution_service = |
| 13471 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13472 | } |
| 13473 | |
| 13474 | HttpRequestInfo request; |
| 13475 | request.method = "GET"; |
| 13476 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13477 | request.traffic_annotation = |
| 13478 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13481 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13482 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13483 | |
| 13484 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13485 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13486 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13487 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13488 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13489 | |
| 13490 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13491 | mock_reads.back().push_back(read_write_round.read); |
| 13492 | mock_writes.back().push_back(read_write_round.write); |
| 13493 | |
| 13494 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13495 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13496 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13497 | mock_reads.push_back(std::vector<MockRead>()); |
| 13498 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13499 | } |
| 13500 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13501 | if (read_write_round.extra_read) { |
| 13502 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13503 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13504 | if (read_write_round.extra_write) { |
| 13505 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13506 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13507 | |
| 13508 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13509 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13510 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13511 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13512 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13513 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13514 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13515 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13516 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13517 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13518 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13519 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13520 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13521 | } |
| 13522 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13523 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13524 | // they are as well. |
| 13525 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13526 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13527 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13528 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13529 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13530 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13531 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13532 | int rv; |
| 13533 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13534 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13535 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13536 | rv = trans.RestartWithAuth( |
| 13537 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13538 | } |
| 13539 | if (rv == ERR_IO_PENDING) |
| 13540 | rv = callback.WaitForResult(); |
| 13541 | |
| 13542 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13543 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13544 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13545 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13546 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13547 | continue; |
| 13548 | } |
| 13549 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13550 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13551 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13552 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13553 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13554 | } |
| 13555 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13556 | } |
| 13557 | } |
| 13558 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13559 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13560 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13561 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13562 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13563 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13564 | session_deps_.proxy_resolution_service = |
| 13565 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13566 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13567 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13568 | |
| 13569 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13570 | auth_handler->set_connection_based(true); |
| 13571 | std::string auth_challenge = "Mock realm=server"; |
| 13572 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13573 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13574 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13575 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13576 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13577 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13578 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13579 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13580 | int rv = OK; |
| 13581 | const HttpResponseInfo* response = NULL; |
| 13582 | HttpRequestInfo request; |
| 13583 | request.method = "GET"; |
| 13584 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13585 | request.traffic_annotation = |
| 13586 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13589 | |
| 13590 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13591 | // to validate that the TCP socket is not released to the pool between |
| 13592 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13593 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13594 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13595 | 50, // Max sockets for pool |
| 13596 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13597 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13598 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13599 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13600 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13601 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13604 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13605 | |
| 13606 | const MockWrite kGet( |
| 13607 | "GET / HTTP/1.1\r\n" |
| 13608 | "Host: www.example.com\r\n" |
| 13609 | "Connection: keep-alive\r\n\r\n"); |
| 13610 | const MockWrite kGetAuth( |
| 13611 | "GET / HTTP/1.1\r\n" |
| 13612 | "Host: www.example.com\r\n" |
| 13613 | "Connection: keep-alive\r\n" |
| 13614 | "Authorization: auth_token\r\n\r\n"); |
| 13615 | |
| 13616 | const MockRead kServerChallenge( |
| 13617 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13618 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13619 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13620 | "Content-Length: 14\r\n\r\n" |
| 13621 | "Unauthorized\r\n"); |
| 13622 | const MockRead kSuccess( |
| 13623 | "HTTP/1.1 200 OK\r\n" |
| 13624 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13625 | "Content-Length: 3\r\n\r\n" |
| 13626 | "Yes"); |
| 13627 | |
| 13628 | MockWrite writes[] = { |
| 13629 | // First round |
| 13630 | kGet, |
| 13631 | // Second round |
| 13632 | kGetAuth, |
| 13633 | // Third round |
| 13634 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13635 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13636 | kGetAuth, |
| 13637 | // Competing request |
| 13638 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13639 | }; |
| 13640 | MockRead reads[] = { |
| 13641 | // First round |
| 13642 | kServerChallenge, |
| 13643 | // Second round |
| 13644 | kServerChallenge, |
| 13645 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13646 | kServerChallenge, |
| 13647 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13648 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13649 | // Competing response |
| 13650 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13651 | }; |
| 13652 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13653 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13654 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13655 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13656 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13657 | |
| 13658 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13659 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13660 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13661 | if (rv == ERR_IO_PENDING) |
| 13662 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13663 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13664 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13665 | ASSERT_TRUE(response); |
| 13666 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13667 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13668 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13669 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13670 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13671 | // In between rounds, another request comes in for the same domain. |
| 13672 | // It should not be able to grab the TCP socket that trans has already |
| 13673 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13674 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13675 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13676 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13677 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13679 | // callback_compete.WaitForResult at this point would stall forever, |
| 13680 | // since the HttpNetworkTransaction does not release the request back to |
| 13681 | // the pool until after authentication completes. |
| 13682 | |
| 13683 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13684 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13685 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13686 | if (rv == ERR_IO_PENDING) |
| 13687 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13688 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13689 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13690 | ASSERT_TRUE(response); |
| 13691 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13692 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13693 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13694 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13695 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13696 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13697 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13698 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13699 | if (rv == ERR_IO_PENDING) |
| 13700 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13701 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13702 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13703 | ASSERT_TRUE(response); |
| 13704 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13705 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13706 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13707 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13708 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13709 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13710 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13711 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13712 | if (rv == ERR_IO_PENDING) |
| 13713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13714 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13715 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13716 | ASSERT_TRUE(response); |
| 13717 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13718 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13719 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13720 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13721 | // auth handler should transition to a DONE state in concert with the remote |
| 13722 | // server. But that's not something we can test here with a mock handler. |
| 13723 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13724 | auth_handler->state()); |
| 13725 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13726 | // Read the body since the fourth round was successful. This will also |
| 13727 | // release the socket back to the pool. |
| 13728 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13729 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13730 | if (rv == ERR_IO_PENDING) |
| 13731 | rv = callback.WaitForResult(); |
| 13732 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13733 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13734 | EXPECT_EQ(0, rv); |
| 13735 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13736 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13737 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13738 | |
| 13739 | // The competing request can now finish. Wait for the headers and then |
| 13740 | // read the body. |
| 13741 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13742 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13743 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13744 | if (rv == ERR_IO_PENDING) |
| 13745 | rv = callback.WaitForResult(); |
| 13746 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13747 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13748 | EXPECT_EQ(0, rv); |
| 13749 | |
| 13750 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13751 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13752 | } |
| 13753 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13754 | // This tests the case that a request is issued via http instead of spdy after |
| 13755 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13756 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13757 | HttpRequestInfo request; |
| 13758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13759 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13760 | request.traffic_annotation = |
| 13761 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13762 | |
| 13763 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13764 | MockWrite( |
| 13765 | "GET / HTTP/1.1\r\n" |
| 13766 | "Host: www.example.org\r\n" |
| 13767 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13768 | }; |
| 13769 | |
| 13770 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13771 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13772 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13773 | MockRead("\r\n"), |
| 13774 | MockRead("hello world"), |
| 13775 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13776 | }; |
| 13777 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13778 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13779 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13780 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13781 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13782 | |
| 13783 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13784 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13787 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13792 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13793 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13795 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13797 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13798 | ASSERT_TRUE(response); |
| 13799 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13800 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13801 | |
| 13802 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13803 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13804 | EXPECT_EQ("hello world", response_data); |
| 13805 | |
| 13806 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13807 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13808 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13809 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13810 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13811 | // immediate server closing of the socket. |
| 13812 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13813 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13814 | HttpRequestInfo request; |
| 13815 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13816 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13817 | request.traffic_annotation = |
| 13818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13819 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13820 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13821 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13822 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13823 | |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 13824 | SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13825 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13826 | |
| 13827 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13828 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13829 | }; |
| 13830 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13831 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13832 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13833 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13835 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13836 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13838 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13839 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13840 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13842 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13843 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13844 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13845 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13846 | // it gets it. This is needed since the auth handler may get destroyed |
| 13847 | // before we get a chance to query it. |
| 13848 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13849 | public: |
| 13850 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13851 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13852 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13853 | |
| 13854 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13855 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13856 | const HttpRequestInfo* request, |
| 13857 | const CompletionCallback& callback, |
| 13858 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13859 | *url_ = request->url; |
| 13860 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13861 | credentials, request, callback, auth_token); |
| 13862 | } |
| 13863 | |
| 13864 | private: |
| 13865 | GURL* url_; |
| 13866 | }; |
| 13867 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13868 | // Test that if we cancel the transaction as the connection is completing, that |
| 13869 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13870 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13871 | // Setup everything about the connection to complete synchronously, so that |
| 13872 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13873 | // for is the callback from the HttpStreamRequest. |
| 13874 | // Then cancel the transaction. |
| 13875 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13876 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13877 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13878 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13879 | MockRead(SYNCHRONOUS, "hello world"), |
| 13880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13881 | }; |
| 13882 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13883 | HttpRequestInfo request; |
| 13884 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13885 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13886 | request.traffic_annotation = |
| 13887 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13888 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13889 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13891 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13892 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13893 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13894 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13895 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13897 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13898 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13899 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13900 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13901 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13902 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13903 | trans.reset(); // Cancel the transaction here. |
| 13904 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13905 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13906 | } |
| 13907 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13908 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13909 | // stream is drained properly and added back to the socket pool. The main |
| 13910 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13911 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13912 | // deleted. |
| 13913 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13914 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13915 | MockRead data_reads[] = { |
| 13916 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13917 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13918 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13919 | MockRead(ASYNC, "1"), |
| 13920 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13921 | // HttpNetworkTransaction has been deleted. |
| 13922 | MockRead(ASYNC, "2"), |
| 13923 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13924 | }; |
| 13925 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13927 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13929 | |
| 13930 | { |
| 13931 | HttpRequestInfo request; |
| 13932 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13933 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13934 | request.traffic_annotation = |
| 13935 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13936 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13938 | TestCompletionCallback callback; |
| 13939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13942 | callback.WaitForResult(); |
| 13943 | |
| 13944 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13945 | ASSERT_TRUE(response); |
| 13946 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13947 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13948 | |
| 13949 | // The transaction and HttpRequestInfo are deleted. |
| 13950 | } |
| 13951 | |
| 13952 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13953 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13954 | |
| 13955 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13956 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13957 | } |
| 13958 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13959 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13960 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13961 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13962 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13963 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13964 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13965 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13967 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13968 | HttpRequestInfo request; |
| 13969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13970 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13971 | request.traffic_annotation = |
| 13972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13973 | |
| 13974 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13975 | MockWrite( |
| 13976 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13977 | "Host: www.example.org\r\n" |
| 13978 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13979 | }; |
| 13980 | |
| 13981 | MockRead data_reads1[] = { |
| 13982 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13983 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13984 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13985 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13986 | }; |
| 13987 | |
| 13988 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13989 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13992 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13995 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13996 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13997 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13998 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14000 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14002 | |
| 14003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [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); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [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(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14013 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14014 | HostPortPair::FromString("myproxy:70")), |
| 14015 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14016 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14017 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14018 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14020 | |
| 14021 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14022 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14023 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14024 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14025 | } |
| 14026 | |
| 14027 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14028 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14029 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14030 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14031 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14032 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14033 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14035 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14036 | HttpRequestInfo request; |
| 14037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14038 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14039 | request.traffic_annotation = |
| 14040 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14041 | |
| 14042 | // Since we have proxy, should try to establish tunnel. |
| 14043 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14044 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14045 | "Host: www.example.org:443\r\n" |
| 14046 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14047 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14048 | MockWrite("GET / HTTP/1.1\r\n" |
| 14049 | "Host: www.example.org\r\n" |
| 14050 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14051 | }; |
| 14052 | |
| 14053 | MockRead data_reads1[] = { |
| 14054 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14055 | |
| 14056 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14057 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14058 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14059 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14060 | }; |
| 14061 | |
| 14062 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14063 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14064 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14065 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14066 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14068 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14071 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14072 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14073 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14074 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14076 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14078 | |
| 14079 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14080 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14081 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14082 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14083 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14084 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14085 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14086 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14087 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14088 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14089 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14091 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14092 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14093 | |
| 14094 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14095 | EXPECT_EQ(200, response->headers->response_code()); |
| 14096 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14097 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14098 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14099 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14100 | HostPortPair::FromString("myproxy:70")), |
| 14101 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14102 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14103 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14104 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14105 | |
| 14106 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14107 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14108 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14109 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14110 | } |
| 14111 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14112 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14113 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14114 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14115 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14116 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14117 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14118 | BoundTestNetLog log; |
| 14119 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14121 | |
| 14122 | HttpRequestInfo request; |
| 14123 | request.method = "GET"; |
| 14124 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14125 | request.traffic_annotation = |
| 14126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14127 | |
| 14128 | // Since we have proxy, should try to establish tunnel. |
| 14129 | MockWrite data_writes1[] = { |
| 14130 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 14131 | "Host: [::1]:443\r\n" |
| 14132 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14133 | |
| 14134 | MockWrite("GET / HTTP/1.1\r\n" |
| 14135 | "Host: [::1]\r\n" |
| 14136 | "Connection: keep-alive\r\n\r\n"), |
| 14137 | }; |
| 14138 | |
| 14139 | MockRead data_reads1[] = { |
| 14140 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14141 | |
| 14142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14143 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14144 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14145 | MockRead(SYNCHRONOUS, OK), |
| 14146 | }; |
| 14147 | |
| 14148 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14149 | data_writes1, arraysize(data_writes1)); |
| 14150 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14151 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14153 | |
| 14154 | TestCompletionCallback callback1; |
| 14155 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14158 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14159 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14160 | |
| 14161 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14162 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14163 | TestNetLogEntry::List entries; |
| 14164 | log.GetEntries(&entries); |
| 14165 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14166 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14167 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14168 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14169 | entries, pos, |
| 14170 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14171 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14173 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14174 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14175 | |
| 14176 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14177 | EXPECT_EQ(200, response->headers->response_code()); |
| 14178 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14179 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14180 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14181 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14182 | HostPortPair::FromString("myproxy:70")), |
| 14183 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14184 | |
| 14185 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14186 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14187 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14188 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14189 | } |
| 14190 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14191 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14192 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14193 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14194 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14195 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14196 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14197 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14199 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14200 | HttpRequestInfo request; |
| 14201 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14202 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14203 | request.traffic_annotation = |
| 14204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14205 | |
| 14206 | // Since we have proxy, should try to establish tunnel. |
| 14207 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14208 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14209 | "Host: www.example.org:443\r\n" |
| 14210 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14211 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14212 | MockWrite("GET / HTTP/1.1\r\n" |
| 14213 | "Host: www.example.org\r\n" |
| 14214 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14215 | }; |
| 14216 | |
| 14217 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14218 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14219 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14220 | }; |
| 14221 | |
| 14222 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14223 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14224 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14225 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14228 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14231 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14232 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14234 | |
| 14235 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14236 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14237 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14238 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14239 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14240 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14241 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14242 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14243 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14244 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14245 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14246 | } |
| 14247 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14248 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14249 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14250 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14251 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14252 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14253 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14254 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14255 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14256 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14257 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14258 | }; |
| 14259 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14260 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 14261 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14262 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14263 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14264 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14265 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14266 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14269 | |
| 14270 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14271 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14272 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14273 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14274 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14275 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14276 | |
| 14277 | HttpRequestInfo request; |
| 14278 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14279 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14280 | request.traffic_annotation = |
| 14281 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14282 | |
| 14283 | // This is the important line that marks this as a preconnect. |
| 14284 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 14285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14287 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14288 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14289 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14290 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14291 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14292 | } |
| 14293 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14294 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14295 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14296 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14297 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14298 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14299 | request_info.url = GURL("https://www.example.com/"); |
| 14300 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14301 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14302 | request_info.traffic_annotation = |
| 14303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14304 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14305 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14306 | MockWrite data_writes[] = { |
| 14307 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14308 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14309 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14310 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14311 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14312 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14313 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14314 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14316 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14317 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14318 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14319 | rv = callback.WaitForResult(); |
| 14320 | ASSERT_EQ(error, rv); |
| 14321 | } |
| 14322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14323 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14324 | // Just check a grab bag of cert errors. |
| 14325 | static const int kErrors[] = { |
| 14326 | ERR_CERT_COMMON_NAME_INVALID, |
| 14327 | ERR_CERT_AUTHORITY_INVALID, |
| 14328 | ERR_CERT_DATE_INVALID, |
| 14329 | }; |
| 14330 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14331 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14332 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14333 | } |
| 14334 | } |
| 14335 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14336 | // Ensure that a client certificate is removed from the SSL client auth |
| 14337 | // cache when: |
| 14338 | // 1) No proxy is involved. |
| 14339 | // 2) TLS False Start is disabled. |
| 14340 | // 3) The initial TLS handshake requests a client certificate. |
| 14341 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14342 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14343 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14344 | request_info.url = GURL("https://www.example.com/"); |
| 14345 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14346 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14347 | request_info.traffic_annotation = |
| 14348 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14349 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14350 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14351 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14352 | |
| 14353 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14354 | // CertificateRequest is received for the first time, the handshake will |
| 14355 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14356 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14357 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14359 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14360 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14361 | |
| 14362 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14363 | // False Start is not being used, the result of the SSL handshake will be |
| 14364 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14365 | // matches the result of a server sending a handshake_failure alert, |
| 14366 | // rather than a Finished message, because it requires a client |
| 14367 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14368 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14369 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14371 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14372 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14373 | |
| 14374 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14375 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14376 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14377 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14378 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14379 | // requiring a client certificate, this fallback handshake should also |
| 14380 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14381 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14382 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14384 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14385 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14386 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14387 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14388 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14389 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14390 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14391 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14392 | // requiring a client certificate, this fallback handshake should also |
| 14393 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14394 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14395 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14397 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14398 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14399 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14401 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14402 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14403 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14404 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14405 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14406 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14407 | |
| 14408 | // Complete the SSL handshake, which should abort due to requiring a |
| 14409 | // client certificate. |
| 14410 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14411 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14412 | |
| 14413 | // Indicate that no certificate should be supplied. From the perspective |
| 14414 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14415 | // certificate, so this is the same as supply a |
| 14416 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14417 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14418 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14419 | |
| 14420 | // Ensure the certificate was added to the client auth cache before |
| 14421 | // allowing the connection to continue restarting. |
| 14422 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14423 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14424 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14425 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14426 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14427 | |
| 14428 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14429 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14430 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14431 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14432 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14433 | |
| 14434 | // Ensure that the client certificate is removed from the cache on a |
| 14435 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14436 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14437 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14438 | } |
| 14439 | |
| 14440 | // Ensure that a client certificate is removed from the SSL client auth |
| 14441 | // cache when: |
| 14442 | // 1) No proxy is involved. |
| 14443 | // 2) TLS False Start is enabled. |
| 14444 | // 3) The initial TLS handshake requests a client certificate. |
| 14445 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14446 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14447 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14448 | request_info.url = GURL("https://www.example.com/"); |
| 14449 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14450 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14451 | request_info.traffic_annotation = |
| 14452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14453 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14454 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14455 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14456 | |
| 14457 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14458 | // return successfully after reading up to the peer's Certificate message. |
| 14459 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14460 | // enqueue application data to be sent in the same packet as the |
| 14461 | // ChangeCipherSpec and Finished messages. |
| 14462 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14463 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14464 | // Finished messages. If there was an error negotiating with the peer, |
| 14465 | // such as due to the peer requiring a client certificate when none was |
| 14466 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14467 | // called. |
| 14468 | |
| 14469 | // Like the non-False Start case, when a client certificate is requested by |
| 14470 | // the peer, the handshake is aborted during the Connect() call. |
| 14471 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14472 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14473 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14475 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14476 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14477 | |
| 14478 | // When a client certificate is supplied, Connect() will not be aborted |
| 14479 | // when the peer requests the certificate. Instead, the handshake will |
| 14480 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14481 | // the socket. The handshake messages are not processed until Read() is |
| 14482 | // called, which then detects that the handshake was aborted, due to the |
| 14483 | // peer sending a handshake_failure because it requires a client |
| 14484 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14485 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14486 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14488 | MockRead data2_reads[] = { |
| 14489 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14490 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14491 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14492 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14493 | |
| 14494 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14495 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14496 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14497 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14498 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14499 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14500 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14501 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14502 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14503 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14504 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14505 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14506 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14508 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14509 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14510 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14511 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14512 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14513 | ssl_data5.cert_request_info = cert_request.get(); |
| 14514 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14515 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14516 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14517 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14518 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14520 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14521 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14522 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14523 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14524 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14525 | |
| 14526 | // Complete the SSL handshake, which should abort due to requiring a |
| 14527 | // client certificate. |
| 14528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14529 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14530 | |
| 14531 | // Indicate that no certificate should be supplied. From the perspective |
| 14532 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14533 | // certificate, so this is the same as supply a |
| 14534 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14535 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14536 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14537 | |
| 14538 | // Ensure the certificate was added to the client auth cache before |
| 14539 | // allowing the connection to continue restarting. |
| 14540 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14541 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14542 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14543 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14544 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14545 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14546 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14547 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14548 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14549 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14550 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14551 | |
| 14552 | // Ensure that the client certificate is removed from the cache on a |
| 14553 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14554 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14555 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14556 | } |
| 14557 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14558 | // Ensure that a client certificate is removed from the SSL client auth |
| 14559 | // cache when: |
| 14560 | // 1) An HTTPS proxy is involved. |
| 14561 | // 3) The HTTPS proxy requests a client certificate. |
| 14562 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14563 | // proxy. |
| 14564 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14565 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14566 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14567 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14568 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14569 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14570 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14571 | |
| 14572 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14573 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14574 | |
| 14575 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14576 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14577 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14578 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14579 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14580 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14582 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14583 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14584 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14585 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14586 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14588 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14589 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14590 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14591 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14592 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14593 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14594 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14595 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14596 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14597 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14598 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14599 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14600 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14601 | requests[0].url = GURL("https://www.example.com/"); |
| 14602 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14603 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14604 | requests[0].traffic_annotation = |
| 14605 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14606 | |
| 14607 | requests[1].url = GURL("http://www.example.com/"); |
| 14608 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14609 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14610 | requests[1].traffic_annotation = |
| 14611 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14612 | |
| 14613 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14614 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14615 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14616 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14617 | |
| 14618 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14619 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14620 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14621 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14622 | |
| 14623 | // Complete the SSL handshake, which should abort due to requiring a |
| 14624 | // client certificate. |
| 14625 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14626 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14627 | |
| 14628 | // Indicate that no certificate should be supplied. From the perspective |
| 14629 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14630 | // certificate, so this is the same as supply a |
| 14631 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14632 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14633 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14634 | |
| 14635 | // Ensure the certificate was added to the client auth cache before |
| 14636 | // allowing the connection to continue restarting. |
| 14637 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14638 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14639 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14640 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14641 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14642 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14643 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14644 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14645 | HostPortPair("www.example.com", 443), &client_cert, |
| 14646 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14647 | |
| 14648 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14649 | // then consume ssl_data3, which should also fail. The result code is |
| 14650 | // checked against what ssl_data3 should return. |
| 14651 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14652 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14653 | |
| 14654 | // Now that the new handshake has failed, ensure that the client |
| 14655 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14656 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14657 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14658 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14659 | HostPortPair("www.example.com", 443), &client_cert, |
| 14660 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14661 | } |
| 14662 | } |
| 14663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14664 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14665 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14666 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14668 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14669 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14670 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14671 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14672 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14673 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14674 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14675 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14676 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14677 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14678 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14679 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14680 | SpdySerializedFrame host1_resp_body( |
| 14681 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14682 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14683 | SpdySerializedFrame host2_resp_body( |
| 14684 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14685 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14686 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14687 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14688 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14689 | }; |
| 14690 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14691 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14692 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14693 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14694 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14695 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14696 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14697 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14698 | HttpRequestInfo request1; |
| 14699 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14700 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14701 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14702 | request1.traffic_annotation = |
| 14703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14704 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14706 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14708 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14709 | |
| 14710 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14711 | ASSERT_TRUE(response); |
| 14712 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14713 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14714 | |
| 14715 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14716 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14717 | EXPECT_EQ("hello!", response_data); |
| 14718 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14719 | // Preload mail.example.com into HostCache. |
| 14720 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14721 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14722 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14723 | std::unique_ptr<HostResolver::Request> request; |
| 14724 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14725 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14726 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14728 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14729 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14730 | |
| 14731 | HttpRequestInfo request2; |
| 14732 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14733 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14734 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14735 | request2.traffic_annotation = |
| 14736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14737 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14739 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14741 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14742 | |
| 14743 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14744 | ASSERT_TRUE(response); |
| 14745 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14746 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14747 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14748 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14749 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14750 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14751 | } |
| 14752 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14753 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14754 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14755 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14757 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14758 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14759 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14760 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14761 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14762 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14763 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14764 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14765 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14766 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14767 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14768 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14769 | SpdySerializedFrame host1_resp_body( |
| 14770 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14771 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14772 | SpdySerializedFrame host2_resp_body( |
| 14773 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14774 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14775 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14776 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14777 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14778 | }; |
| 14779 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14780 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14781 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14782 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14783 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14784 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14785 | |
| 14786 | TestCompletionCallback callback; |
| 14787 | HttpRequestInfo request1; |
| 14788 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14789 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14790 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14791 | request1.traffic_annotation = |
| 14792 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14793 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14795 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14797 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14798 | |
| 14799 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14800 | ASSERT_TRUE(response); |
| 14801 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14802 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14803 | |
| 14804 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14805 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14806 | EXPECT_EQ("hello!", response_data); |
| 14807 | |
| 14808 | HttpRequestInfo request2; |
| 14809 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14810 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14811 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14812 | request2.traffic_annotation = |
| 14813 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14814 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14816 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14818 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14819 | |
| 14820 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14821 | ASSERT_TRUE(response); |
| 14822 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14823 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14824 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14825 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14826 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14827 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14828 | } |
| 14829 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14830 | // Regression test for https://crbug.com/546991. |
| 14831 | // The server might not be able to serve an IP pooled request, and might send a |
| 14832 | // 421 Misdirected Request response status to indicate this. |
| 14833 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14834 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14835 | // Two hosts resolve to the same IP address. |
| 14836 | const std::string ip_addr = "1.2.3.4"; |
| 14837 | IPAddress ip; |
| 14838 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14839 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14840 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14841 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14842 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14843 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14844 | |
| 14845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14846 | |
| 14847 | // Two requests on the first connection. |
| 14848 | SpdySerializedFrame req1( |
| 14849 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14850 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14851 | SpdySerializedFrame req2( |
| 14852 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14853 | SpdySerializedFrame rst( |
| 14854 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14855 | MockWrite writes1[] = { |
| 14856 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14857 | CreateMockWrite(rst, 6), |
| 14858 | }; |
| 14859 | |
| 14860 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14861 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14862 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14863 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14864 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14865 | SpdySerializedFrame resp2( |
| 14866 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14867 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14868 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14869 | |
| 14870 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14871 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14872 | arraysize(writes1)); |
| 14873 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14874 | |
| 14875 | AddSSLSocketData(); |
| 14876 | |
| 14877 | // Retry the second request on a second connection. |
| 14878 | SpdyTestUtil spdy_util2; |
| 14879 | SpdySerializedFrame req3( |
| 14880 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14881 | MockWrite writes2[] = { |
| 14882 | CreateMockWrite(req3, 0), |
| 14883 | }; |
| 14884 | |
| 14885 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14886 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14887 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14888 | MockRead(ASYNC, 0, 3)}; |
| 14889 | |
| 14890 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14891 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14892 | arraysize(writes2)); |
| 14893 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14894 | |
| 14895 | AddSSLSocketData(); |
| 14896 | |
| 14897 | // Preload mail.example.org into HostCache. |
| 14898 | HostPortPair host_port("mail.example.org", 443); |
| 14899 | HostResolver::RequestInfo resolve_info(host_port); |
| 14900 | AddressList ignored; |
| 14901 | std::unique_ptr<HostResolver::Request> request; |
| 14902 | TestCompletionCallback callback; |
| 14903 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14904 | &ignored, callback.callback(), |
| 14905 | &request, NetLogWithSource()); |
| 14906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14907 | rv = callback.WaitForResult(); |
| 14908 | EXPECT_THAT(rv, IsOk()); |
| 14909 | |
| 14910 | HttpRequestInfo request1; |
| 14911 | request1.method = "GET"; |
| 14912 | request1.url = GURL("https://www.example.org/"); |
| 14913 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14914 | request1.traffic_annotation = |
| 14915 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14916 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14917 | |
| 14918 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14920 | rv = callback.WaitForResult(); |
| 14921 | EXPECT_THAT(rv, IsOk()); |
| 14922 | |
| 14923 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14924 | ASSERT_TRUE(response); |
| 14925 | ASSERT_TRUE(response->headers); |
| 14926 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14927 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14928 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14929 | std::string response_data; |
| 14930 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14931 | EXPECT_EQ("hello!", response_data); |
| 14932 | |
| 14933 | HttpRequestInfo request2; |
| 14934 | request2.method = "GET"; |
| 14935 | request2.url = GURL("https://mail.example.org/"); |
| 14936 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14937 | request2.traffic_annotation = |
| 14938 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14939 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14940 | |
| 14941 | BoundTestNetLog log; |
| 14942 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14944 | rv = callback.WaitForResult(); |
| 14945 | EXPECT_THAT(rv, IsOk()); |
| 14946 | |
| 14947 | response = trans2.GetResponseInfo(); |
| 14948 | ASSERT_TRUE(response); |
| 14949 | ASSERT_TRUE(response->headers); |
| 14950 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14951 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14952 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14953 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14954 | EXPECT_EQ("hello!", response_data); |
| 14955 | |
| 14956 | TestNetLogEntry::List entries; |
| 14957 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14958 | ExpectLogContainsSomewhere( |
| 14959 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14960 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14961 | } |
| 14962 | |
| 14963 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14964 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14965 | // portions of the response. |
| 14966 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14967 | // Two hosts resolve to the same IP address. |
| 14968 | const std::string ip_addr = "1.2.3.4"; |
| 14969 | IPAddress ip; |
| 14970 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14971 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14972 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14973 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14974 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14975 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14976 | |
| 14977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14978 | |
| 14979 | // Two requests on the first connection. |
| 14980 | SpdySerializedFrame req1( |
| 14981 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14982 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14983 | SpdySerializedFrame req2( |
| 14984 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14985 | SpdySerializedFrame rst( |
| 14986 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14987 | MockWrite writes1[] = { |
| 14988 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14989 | CreateMockWrite(rst, 6), |
| 14990 | }; |
| 14991 | |
| 14992 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14993 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14994 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14995 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14996 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14997 | SpdySerializedFrame resp2( |
| 14998 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14999 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15000 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15001 | |
| 15002 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 15003 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 15004 | arraysize(writes1)); |
| 15005 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15006 | |
| 15007 | AddSSLSocketData(); |
| 15008 | |
| 15009 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15010 | // Retry again. |
| 15011 | SpdyTestUtil spdy_util2; |
| 15012 | SpdySerializedFrame req3( |
| 15013 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15014 | MockWrite writes2[] = { |
| 15015 | CreateMockWrite(req3, 0), |
| 15016 | }; |
| 15017 | |
| 15018 | SpdySerializedFrame resp3( |
| 15019 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 15020 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 15021 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15022 | MockRead(ASYNC, 0, 3)}; |
| 15023 | |
| 15024 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 15025 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 15026 | arraysize(writes2)); |
| 15027 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15028 | |
| 15029 | AddSSLSocketData(); |
| 15030 | |
| 15031 | // Preload mail.example.org into HostCache. |
| 15032 | HostPortPair host_port("mail.example.org", 443); |
| 15033 | HostResolver::RequestInfo resolve_info(host_port); |
| 15034 | AddressList ignored; |
| 15035 | std::unique_ptr<HostResolver::Request> request; |
| 15036 | TestCompletionCallback callback; |
| 15037 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15038 | &ignored, callback.callback(), |
| 15039 | &request, NetLogWithSource()); |
| 15040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15041 | rv = callback.WaitForResult(); |
| 15042 | EXPECT_THAT(rv, IsOk()); |
| 15043 | |
| 15044 | HttpRequestInfo request1; |
| 15045 | request1.method = "GET"; |
| 15046 | request1.url = GURL("https://www.example.org/"); |
| 15047 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15048 | request1.traffic_annotation = |
| 15049 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15050 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15051 | |
| 15052 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15054 | rv = callback.WaitForResult(); |
| 15055 | EXPECT_THAT(rv, IsOk()); |
| 15056 | |
| 15057 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15058 | ASSERT_TRUE(response); |
| 15059 | ASSERT_TRUE(response->headers); |
| 15060 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15061 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15062 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15063 | std::string response_data; |
| 15064 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15065 | EXPECT_EQ("hello!", response_data); |
| 15066 | |
| 15067 | HttpRequestInfo request2; |
| 15068 | request2.method = "GET"; |
| 15069 | request2.url = GURL("https://mail.example.org/"); |
| 15070 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15071 | request2.traffic_annotation = |
| 15072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15073 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15074 | |
| 15075 | BoundTestNetLog log; |
| 15076 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15078 | rv = callback.WaitForResult(); |
| 15079 | EXPECT_THAT(rv, IsOk()); |
| 15080 | |
| 15081 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15082 | // caller. |
| 15083 | response = trans2.GetResponseInfo(); |
| 15084 | ASSERT_TRUE(response); |
| 15085 | ASSERT_TRUE(response->headers); |
| 15086 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15087 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15088 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15089 | EXPECT_TRUE(response->ssl_info.cert); |
| 15090 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15091 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15092 | } |
| 15093 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15094 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15095 | public: |
| 15096 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15097 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15098 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15099 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15100 | int ResolveFromCache(const RequestInfo& info, |
| 15101 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15102 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15103 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 15104 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15105 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15106 | return rv; |
| 15107 | } |
| 15108 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15109 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15110 | const HostPortPair host_port_; |
| 15111 | }; |
| 15112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15113 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15114 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15115 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15116 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15117 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15119 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15120 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15121 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15122 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15123 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15124 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15125 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15126 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15127 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15128 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15129 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15130 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15131 | SpdySerializedFrame host1_resp_body( |
| 15132 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15133 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15134 | SpdySerializedFrame host2_resp_body( |
| 15135 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15136 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15137 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15138 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15139 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15140 | }; |
| 15141 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15142 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15143 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15144 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 15145 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15146 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15147 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15148 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15149 | HttpRequestInfo request1; |
| 15150 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15151 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15152 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15153 | request1.traffic_annotation = |
| 15154 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15155 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15157 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15159 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15160 | |
| 15161 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15162 | ASSERT_TRUE(response); |
| 15163 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15164 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15165 | |
| 15166 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15167 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15168 | EXPECT_EQ("hello!", response_data); |
| 15169 | |
| 15170 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15171 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15172 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15173 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15174 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15175 | &ignored, callback.callback(), |
| 15176 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15178 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15180 | |
| 15181 | HttpRequestInfo request2; |
| 15182 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15183 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15184 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15185 | request2.traffic_annotation = |
| 15186 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15187 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15188 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15189 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15190 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15191 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15192 | |
| 15193 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15194 | ASSERT_TRUE(response); |
| 15195 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15196 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15197 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15198 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15199 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15200 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15201 | } |
| 15202 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15203 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15204 | const std::string https_url = "https://www.example.org:8080/"; |
| 15205 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15206 | |
| 15207 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15208 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15209 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15210 | |
| 15211 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15212 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15213 | }; |
| 15214 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15215 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15216 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15217 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15218 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15219 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15220 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15221 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15222 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15223 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15224 | |
| 15225 | // HTTP GET for the HTTP URL |
| 15226 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15227 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15228 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15229 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15230 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15231 | }; |
| 15232 | |
| 15233 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15234 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15235 | MockRead(ASYNC, 2, "hello"), |
| 15236 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15237 | }; |
| 15238 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15239 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15240 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15241 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15242 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15243 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15244 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15246 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15247 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15249 | |
| 15250 | // Start the first transaction to set up the SpdySession |
| 15251 | HttpRequestInfo request1; |
| 15252 | request1.method = "GET"; |
| 15253 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15254 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15255 | request1.traffic_annotation = |
| 15256 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15257 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15258 | TestCompletionCallback callback1; |
| 15259 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15260 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15261 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15262 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15263 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15264 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15265 | |
| 15266 | // Now, start the HTTP request |
| 15267 | HttpRequestInfo request2; |
| 15268 | request2.method = "GET"; |
| 15269 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15270 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15271 | request2.traffic_annotation = |
| 15272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15273 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15274 | TestCompletionCallback callback2; |
| 15275 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15276 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15277 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15278 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15279 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15280 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15281 | } |
| 15282 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15283 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15284 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15285 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15286 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15287 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15288 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15289 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15290 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15291 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15293 | |
| 15294 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15295 | // negotiated. |
| 15296 | StaticSocketDataProvider data; |
| 15297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15298 | |
| 15299 | // 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] | 15300 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15301 | // mocked. This way the request relies on the alternate Job. |
| 15302 | StaticSocketDataProvider data_refused; |
| 15303 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15304 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15305 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15306 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15307 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15308 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15309 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15310 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15311 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15312 | http_server_properties->SetHttp2AlternativeService( |
| 15313 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15314 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15315 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15316 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15317 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15318 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15319 | request.traffic_annotation = |
| 15320 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15321 | TestCompletionCallback callback; |
| 15322 | |
| 15323 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15324 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15325 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15326 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15327 | } |
| 15328 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15329 | // 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] | 15330 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15331 | // succeeds, the request should succeed, even if the latter fails because |
| 15332 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15333 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15334 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15335 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15336 | |
| 15337 | // Negotiate HTTP/1.1 with alternative. |
| 15338 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15339 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15341 | |
| 15342 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15343 | // negotiated. |
| 15344 | StaticSocketDataProvider data; |
| 15345 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15346 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15347 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15348 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15349 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15351 | |
| 15352 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15353 | MockWrite("GET / HTTP/1.1\r\n" |
| 15354 | "Host: www.example.org\r\n" |
| 15355 | "Connection: keep-alive\r\n\r\n"), |
| 15356 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15357 | "Host: www.example.org\r\n" |
| 15358 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15359 | }; |
| 15360 | |
| 15361 | MockRead http_reads[] = { |
| 15362 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15363 | MockRead("Content-Type: text/html\r\n"), |
| 15364 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15365 | MockRead("foobar"), |
| 15366 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15367 | MockRead("Content-Type: text/html\r\n"), |
| 15368 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15369 | MockRead("another"), |
| 15370 | }; |
| 15371 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15372 | http_writes, arraysize(http_writes)); |
| 15373 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15374 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15375 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15377 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15378 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15379 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15380 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15381 | http_server_properties->SetHttp2AlternativeService( |
| 15382 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15383 | |
| 15384 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15385 | HttpRequestInfo request1; |
| 15386 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15387 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15388 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15389 | request1.traffic_annotation = |
| 15390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15391 | TestCompletionCallback callback1; |
| 15392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15393 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15394 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15395 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15396 | |
| 15397 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15398 | ASSERT_TRUE(response1); |
| 15399 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15400 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15401 | |
| 15402 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15403 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15404 | EXPECT_EQ("foobar", response_data1); |
| 15405 | |
| 15406 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15407 | // for alternative service. |
| 15408 | EXPECT_TRUE( |
| 15409 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15410 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15411 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15412 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15413 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15414 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15415 | HttpRequestInfo request2; |
| 15416 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15417 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15418 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15419 | request2.traffic_annotation = |
| 15420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15421 | TestCompletionCallback callback2; |
| 15422 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15423 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15424 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15425 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15426 | |
| 15427 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15428 | ASSERT_TRUE(response2); |
| 15429 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15430 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15431 | |
| 15432 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15433 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15434 | EXPECT_EQ("another", response_data2); |
| 15435 | } |
| 15436 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15437 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15438 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15439 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15440 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15441 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15442 | HostPortPair alternative("alternative.example.org", 443); |
| 15443 | std::string origin_url = "https://origin.example.org:443"; |
| 15444 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15445 | |
| 15446 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15447 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15448 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15449 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15450 | |
| 15451 | // HTTP/1.1 data for |request1| and |request2|. |
| 15452 | MockWrite http_writes[] = { |
| 15453 | MockWrite( |
| 15454 | "GET / HTTP/1.1\r\n" |
| 15455 | "Host: alternative.example.org\r\n" |
| 15456 | "Connection: keep-alive\r\n\r\n"), |
| 15457 | MockWrite( |
| 15458 | "GET / HTTP/1.1\r\n" |
| 15459 | "Host: alternative.example.org\r\n" |
| 15460 | "Connection: keep-alive\r\n\r\n"), |
| 15461 | }; |
| 15462 | |
| 15463 | MockRead http_reads[] = { |
| 15464 | MockRead( |
| 15465 | "HTTP/1.1 200 OK\r\n" |
| 15466 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15467 | "Content-Length: 40\r\n\r\n" |
| 15468 | "first HTTP/1.1 response from alternative"), |
| 15469 | MockRead( |
| 15470 | "HTTP/1.1 200 OK\r\n" |
| 15471 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15472 | "Content-Length: 41\r\n\r\n" |
| 15473 | "second HTTP/1.1 response from alternative"), |
| 15474 | }; |
| 15475 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15476 | http_writes, arraysize(http_writes)); |
| 15477 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15478 | |
| 15479 | // This test documents that an alternate Job should not pool to an already |
| 15480 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15481 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15482 | StaticSocketDataProvider data_refused; |
| 15483 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15484 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15485 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15486 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15488 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15489 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15490 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15491 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15492 | http_server_properties->SetHttp2AlternativeService( |
| 15493 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15494 | |
| 15495 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15496 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15497 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15498 | request1.method = "GET"; |
| 15499 | request1.url = GURL(alternative_url); |
| 15500 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15501 | request1.traffic_annotation = |
| 15502 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15503 | TestCompletionCallback callback1; |
| 15504 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15505 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15506 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15507 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15508 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15509 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15510 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15511 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15512 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15513 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15514 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15515 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15516 | |
| 15517 | // Request for origin.example.org, which has an alternative service. This |
| 15518 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15519 | // 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] | 15520 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15521 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15522 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15523 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15524 | request2.method = "GET"; |
| 15525 | request2.url = GURL(origin_url); |
| 15526 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15527 | request2.traffic_annotation = |
| 15528 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15529 | TestCompletionCallback callback2; |
| 15530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15531 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15532 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15533 | |
| 15534 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15535 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15536 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15537 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15538 | request3.method = "GET"; |
| 15539 | request3.url = GURL(alternative_url); |
| 15540 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15541 | request3.traffic_annotation = |
| 15542 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15543 | TestCompletionCallback callback3; |
| 15544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15545 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15546 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15547 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15548 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15549 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15550 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15551 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15552 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15553 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15554 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15555 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15556 | } |
| 15557 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15558 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15559 | const std::string https_url = "https://www.example.org:8080/"; |
| 15560 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15561 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15562 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15563 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15564 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15565 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15566 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15567 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15568 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15569 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15570 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15571 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15572 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15573 | |
| 15574 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15575 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15576 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15577 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15578 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15579 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15580 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15581 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15582 | |
| 15583 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15584 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15585 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15586 | }; |
| 15587 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15588 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15589 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15590 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15591 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15592 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15593 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15594 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15595 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15596 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15597 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15598 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15599 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15600 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15601 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15602 | CreateMockRead(wrapped_resp1, 4), |
| 15603 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15604 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15605 | CreateMockRead(resp2, 8), |
| 15606 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15607 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15608 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15609 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15610 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15611 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15612 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15613 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15614 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15615 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15616 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15617 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15618 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15619 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15620 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15621 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15623 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15624 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15626 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15628 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15629 | |
| 15630 | // Start the first transaction to set up the SpdySession |
| 15631 | HttpRequestInfo request1; |
| 15632 | request1.method = "GET"; |
| 15633 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15634 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15635 | request1.traffic_annotation = |
| 15636 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15637 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15638 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15639 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15640 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15641 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15642 | data1.RunUntilPaused(); |
| 15643 | base::RunLoop().RunUntilIdle(); |
| 15644 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15645 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15646 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15647 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15648 | LoadTimingInfo load_timing_info1; |
| 15649 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15650 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15651 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15652 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15653 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15654 | HttpRequestInfo request2; |
| 15655 | request2.method = "GET"; |
| 15656 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15657 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15658 | request2.traffic_annotation = |
| 15659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15660 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15661 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15662 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15663 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15664 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15665 | data1.RunUntilPaused(); |
| 15666 | base::RunLoop().RunUntilIdle(); |
| 15667 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15668 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15669 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15670 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15671 | |
| 15672 | LoadTimingInfo load_timing_info2; |
| 15673 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15674 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15675 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15676 | // HTTP requests over a SPDY session should have a different connection |
| 15677 | // socket_log_id than requests over a tunnel. |
| 15678 | 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] | 15679 | } |
| 15680 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15681 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15682 | // that we do not pool other origins that resolve to the same IP when |
| 15683 | // the certificate does not match the new origin. |
| 15684 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15685 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15686 | const std::string url1 = "http://www.example.org/"; |
| 15687 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15688 | const std::string ip_addr = "1.2.3.4"; |
| 15689 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15690 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15691 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15692 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15693 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15694 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15695 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15696 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15697 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15698 | |
| 15699 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15700 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15701 | }; |
| 15702 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15703 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15704 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15705 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15706 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15707 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15708 | }; |
| 15709 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15710 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15711 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15712 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15713 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15714 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15715 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15716 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15717 | |
| 15718 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15719 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15720 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15721 | |
| 15722 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15723 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15724 | }; |
| 15725 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15726 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15727 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15728 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15729 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15730 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15731 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15732 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15733 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15734 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15735 | |
| 15736 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15737 | // all others direct. |
| 15738 | ProxyConfig proxy_config; |
| 15739 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15740 | session_deps_.proxy_resolution_service = |
| 15741 | std::make_unique<ProxyResolutionService>( |
| 15742 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15743 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15744 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15745 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15746 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15747 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15748 | // Load a valid cert. Note, that this does not need to |
| 15749 | // be valid for proxy because the MockSSLClientSocket does |
| 15750 | // not actually verify it. But SpdySession will use this |
| 15751 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15752 | ssl1.ssl_info.cert = |
| 15753 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15754 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15756 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15757 | |
| 15758 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15759 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15761 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15762 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15763 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15764 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15765 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15767 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15768 | |
| 15769 | // Start the first transaction to set up the SpdySession |
| 15770 | HttpRequestInfo request1; |
| 15771 | request1.method = "GET"; |
| 15772 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15773 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15774 | request1.traffic_annotation = |
| 15775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15776 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15777 | TestCompletionCallback callback1; |
| 15778 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15779 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15780 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15781 | data1.RunUntilPaused(); |
| 15782 | base::RunLoop().RunUntilIdle(); |
| 15783 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15784 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15785 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15786 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15787 | |
| 15788 | // Now, start the HTTP request |
| 15789 | HttpRequestInfo request2; |
| 15790 | request2.method = "GET"; |
| 15791 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15792 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15793 | request2.traffic_annotation = |
| 15794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15795 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15796 | TestCompletionCallback callback2; |
| 15797 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15798 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15799 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15800 | |
| 15801 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15802 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15803 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15804 | } |
| 15805 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15806 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15807 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15808 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15809 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15810 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15811 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15812 | |
| 15813 | MockRead reads1[] = { |
| 15814 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15815 | }; |
| 15816 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15817 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15818 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15819 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15820 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15821 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15822 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15823 | }; |
| 15824 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15825 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15826 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15827 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15828 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15829 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15830 | }; |
| 15831 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15832 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15833 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15834 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15835 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15836 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15838 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15839 | |
| 15840 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15841 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15842 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15843 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15845 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15846 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15847 | |
| 15848 | // Start the first transaction to set up the SpdySession and verify that |
| 15849 | // connection was closed. |
| 15850 | HttpRequestInfo request1; |
| 15851 | request1.method = "GET"; |
| 15852 | request1.url = GURL(https_url); |
| 15853 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15854 | request1.traffic_annotation = |
| 15855 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15856 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15857 | TestCompletionCallback callback1; |
| 15858 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15859 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15860 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15861 | |
| 15862 | // Now, start the second request and make sure it succeeds. |
| 15863 | HttpRequestInfo request2; |
| 15864 | request2.method = "GET"; |
| 15865 | request2.url = GURL(https_url); |
| 15866 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15867 | request2.traffic_annotation = |
| 15868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15869 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15870 | TestCompletionCallback callback2; |
| 15871 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15872 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15873 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15874 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15875 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15876 | } |
| 15877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15878 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15879 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15880 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15881 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15882 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15883 | |
| 15884 | // Use two different hosts with different IPs so they don't get pooled. |
| 15885 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15886 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15888 | |
| 15889 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15890 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15891 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15892 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15895 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15896 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15897 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15898 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15899 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15900 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15901 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15902 | SpdySerializedFrame host1_resp_body( |
| 15903 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15904 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15905 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15906 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15907 | }; |
| 15908 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15909 | // Use a separate test instance for the separate SpdySession that will be |
| 15910 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15911 | SpdyTestUtil spdy_util_2; |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15912 | SequencedSocketData spdy1_data(spdy1_reads, arraysize(spdy1_reads), |
| 15913 | spdy1_writes, arraysize(spdy1_writes)); |
| 15914 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15915 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15916 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15917 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15918 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15919 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15920 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15921 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15922 | SpdySerializedFrame host2_resp_body( |
| 15923 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15924 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15925 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15926 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15927 | }; |
| 15928 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15929 | SequencedSocketData spdy2_data(spdy2_reads, arraysize(spdy2_reads), |
| 15930 | spdy2_writes, arraysize(spdy2_writes)); |
| 15931 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15932 | |
| 15933 | MockWrite http_write[] = { |
| 15934 | MockWrite("GET / HTTP/1.1\r\n" |
| 15935 | "Host: www.a.com\r\n" |
| 15936 | "Connection: keep-alive\r\n\r\n"), |
| 15937 | }; |
| 15938 | |
| 15939 | MockRead http_read[] = { |
| 15940 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15941 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15942 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15943 | MockRead("hello!"), |
| 15944 | }; |
| 15945 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15946 | http_write, arraysize(http_write)); |
| 15947 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15948 | |
| 15949 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15950 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15951 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15952 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15953 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15954 | |
| 15955 | TestCompletionCallback callback; |
| 15956 | HttpRequestInfo request1; |
| 15957 | request1.method = "GET"; |
| 15958 | request1.url = GURL("https://www.a.com/"); |
| 15959 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15960 | request1.traffic_annotation = |
| 15961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15962 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15963 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15964 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15965 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15966 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15967 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15968 | |
| 15969 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15970 | ASSERT_TRUE(response); |
| 15971 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15972 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15973 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15974 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15975 | |
| 15976 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15977 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15978 | EXPECT_EQ("hello!", response_data); |
| 15979 | trans.reset(); |
| 15980 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15981 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15982 | |
| 15983 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15984 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15985 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15986 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15987 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15988 | HttpRequestInfo request2; |
| 15989 | request2.method = "GET"; |
| 15990 | request2.url = GURL("https://www.b.com/"); |
| 15991 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15992 | request2.traffic_annotation = |
| 15993 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15994 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15995 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15997 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15999 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16000 | |
| 16001 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16002 | ASSERT_TRUE(response); |
| 16003 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16004 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16005 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16006 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16007 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16008 | EXPECT_EQ("hello!", response_data); |
| 16009 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16010 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16011 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16012 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16013 | |
| 16014 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 16015 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 16016 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16017 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16018 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16019 | HttpRequestInfo request3; |
| 16020 | request3.method = "GET"; |
| 16021 | request3.url = GURL("http://www.a.com/"); |
| 16022 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16023 | request3.traffic_annotation = |
| 16024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16025 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16026 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16027 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16028 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16029 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16030 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16031 | |
| 16032 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16033 | ASSERT_TRUE(response); |
| 16034 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16035 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16036 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16037 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16038 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16039 | EXPECT_EQ("hello!", response_data); |
| 16040 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16041 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16042 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16043 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16044 | } |
| 16045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16046 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[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 | b5e433e | 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 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16056 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16057 | StaticSocketDataProvider data; |
| 16058 | data.set_connect_data(mock_connect); |
| 16059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16060 | |
| 16061 | TestCompletionCallback callback; |
| 16062 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16063 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16065 | |
| 16066 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16067 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16068 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16069 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16070 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16071 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16072 | |
| 16073 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16074 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16075 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16076 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16077 | |
| 16078 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16079 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16080 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16081 | } |
| 16082 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16083 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16084 | HttpRequestInfo request; |
| 16085 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16086 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 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 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16093 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16094 | StaticSocketDataProvider data; |
| 16095 | data.set_connect_data(mock_connect); |
| 16096 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16097 | |
| 16098 | TestCompletionCallback callback; |
| 16099 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16100 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16102 | |
| 16103 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16104 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16105 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16106 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16107 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16108 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16109 | |
| 16110 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16111 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16112 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16113 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16114 | |
| 16115 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16116 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16117 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16118 | } |
| 16119 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16120 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16121 | HttpRequestInfo request; |
| 16122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16123 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16124 | request.traffic_annotation = |
| 16125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16126 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16127 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16129 | |
| 16130 | MockWrite data_writes[] = { |
| 16131 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16132 | }; |
| 16133 | MockRead data_reads[] = { |
| 16134 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16135 | }; |
| 16136 | |
| 16137 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16138 | data_writes, arraysize(data_writes)); |
| 16139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16140 | |
| 16141 | TestCompletionCallback callback; |
| 16142 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16143 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16145 | |
| 16146 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16147 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16148 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16149 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16150 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16151 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16152 | } |
| 16153 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16154 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16155 | HttpRequestInfo request; |
| 16156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16157 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16158 | request.traffic_annotation = |
| 16159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16160 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16163 | |
| 16164 | MockWrite data_writes[] = { |
| 16165 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16166 | }; |
| 16167 | MockRead data_reads[] = { |
| 16168 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16169 | }; |
| 16170 | |
| 16171 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16172 | data_writes, arraysize(data_writes)); |
| 16173 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16174 | |
| 16175 | TestCompletionCallback callback; |
| 16176 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16177 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16179 | |
| 16180 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16181 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16182 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16183 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16184 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16185 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16186 | } |
| 16187 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16188 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16189 | HttpRequestInfo request; |
| 16190 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16191 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16192 | request.traffic_annotation = |
| 16193 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16194 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16195 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16197 | |
| 16198 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16199 | MockWrite( |
| 16200 | "GET / HTTP/1.1\r\n" |
| 16201 | "Host: www.example.org\r\n" |
| 16202 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16203 | }; |
| 16204 | MockRead data_reads[] = { |
| 16205 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16206 | }; |
| 16207 | |
| 16208 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16209 | data_writes, arraysize(data_writes)); |
| 16210 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16211 | |
| 16212 | TestCompletionCallback callback; |
| 16213 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16214 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16215 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16216 | |
| 16217 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16219 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16220 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16221 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16222 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16223 | } |
| 16224 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16225 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16226 | HttpRequestInfo request; |
| 16227 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16228 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16229 | request.traffic_annotation = |
| 16230 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16231 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16234 | |
| 16235 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16236 | MockWrite( |
| 16237 | "GET / HTTP/1.1\r\n" |
| 16238 | "Host: www.example.org\r\n" |
| 16239 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16240 | }; |
| 16241 | MockRead data_reads[] = { |
| 16242 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16243 | }; |
| 16244 | |
| 16245 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16246 | data_writes, arraysize(data_writes)); |
| 16247 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16248 | |
| 16249 | TestCompletionCallback callback; |
| 16250 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16251 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16253 | |
| 16254 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16255 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16256 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16257 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16258 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16259 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16260 | } |
| 16261 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16262 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16263 | HttpRequestInfo request; |
| 16264 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16265 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16266 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16267 | request.traffic_annotation = |
| 16268 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16269 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16270 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16271 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16272 | |
| 16273 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16274 | MockWrite( |
| 16275 | "GET / HTTP/1.1\r\n" |
| 16276 | "Host: www.example.org\r\n" |
| 16277 | "Connection: keep-alive\r\n" |
| 16278 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16279 | }; |
| 16280 | MockRead data_reads[] = { |
| 16281 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16282 | "Content-Length: 5\r\n\r\n" |
| 16283 | "hello"), |
| 16284 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16285 | }; |
| 16286 | |
| 16287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16288 | data_writes, arraysize(data_writes)); |
| 16289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16290 | |
| 16291 | TestCompletionCallback callback; |
| 16292 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16294 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16295 | |
| 16296 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16297 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16298 | |
| 16299 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16300 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16301 | std::string foo; |
| 16302 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16303 | EXPECT_EQ("bar", foo); |
| 16304 | } |
| 16305 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16306 | namespace { |
| 16307 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16308 | // Fake HttpStream that simply records calls to SetPriority(). |
| 16309 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16310 | public base::SupportsWeakPtr<FakeStream> { |
| 16311 | public: |
| 16312 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16313 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16314 | |
| 16315 | RequestPriority priority() const { return priority_; } |
| 16316 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16317 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16318 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16319 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16320 | const NetLogWithSource& net_log, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16321 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16322 | return ERR_IO_PENDING; |
| 16323 | } |
| 16324 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16325 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 16326 | HttpResponseInfo* response, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16327 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16328 | ADD_FAILURE(); |
| 16329 | return ERR_UNEXPECTED; |
| 16330 | } |
| 16331 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16332 | int ReadResponseHeaders(CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16333 | ADD_FAILURE(); |
| 16334 | return ERR_UNEXPECTED; |
| 16335 | } |
| 16336 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16337 | int ReadResponseBody(IOBuffer* buf, |
| 16338 | int buf_len, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16339 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16340 | ADD_FAILURE(); |
| 16341 | return ERR_UNEXPECTED; |
| 16342 | } |
| 16343 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16344 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16345 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16346 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16347 | ADD_FAILURE(); |
| 16348 | return false; |
| 16349 | } |
| 16350 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16351 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16352 | ADD_FAILURE(); |
| 16353 | return false; |
| 16354 | } |
| 16355 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16356 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16357 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16358 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16359 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16360 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 16361 | ADD_FAILURE(); |
| 16362 | return 0; |
| 16363 | } |
| 16364 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16365 | int64_t GetTotalSentBytes() const override { |
| 16366 | ADD_FAILURE(); |
| 16367 | return 0; |
| 16368 | } |
| 16369 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16370 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16371 | ADD_FAILURE(); |
| 16372 | return false; |
| 16373 | } |
| 16374 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16375 | bool GetAlternativeService( |
| 16376 | AlternativeService* alternative_service) const override { |
| 16377 | ADD_FAILURE(); |
| 16378 | return false; |
| 16379 | } |
| 16380 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16381 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 16382 | |
| 16383 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16384 | ADD_FAILURE(); |
| 16385 | } |
| 16386 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16387 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16388 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16389 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16390 | TokenBindingType tb_type, |
| 16391 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16392 | ADD_FAILURE(); |
| 16393 | return ERR_NOT_IMPLEMENTED; |
| 16394 | } |
| 16395 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16396 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16397 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16398 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16399 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16400 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16401 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16402 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 16403 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 16404 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 16405 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16406 | private: |
| 16407 | RequestPriority priority_; |
| 16408 | |
| 16409 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 16410 | }; |
| 16411 | |
| 16412 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 16413 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16414 | class FakeStreamRequest : public HttpStreamRequest, |
| 16415 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 16416 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16417 | FakeStreamRequest(RequestPriority priority, |
| 16418 | HttpStreamRequest::Delegate* delegate) |
| 16419 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16420 | delegate_(delegate), |
| 16421 | websocket_stream_create_helper_(NULL) {} |
| 16422 | |
| 16423 | FakeStreamRequest(RequestPriority priority, |
| 16424 | HttpStreamRequest::Delegate* delegate, |
| 16425 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 16426 | : priority_(priority), |
| 16427 | delegate_(delegate), |
| 16428 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16429 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16430 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16431 | |
| 16432 | RequestPriority priority() const { return priority_; } |
| 16433 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16434 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 16435 | websocket_stream_create_helper() const { |
| 16436 | return websocket_stream_create_helper_; |
| 16437 | } |
| 16438 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16439 | // Create a new FakeStream and pass it to the request's |
| 16440 | // delegate. Returns a weak pointer to the FakeStream. |
| 16441 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16442 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16443 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 16444 | // immediately delete |fake_stream|. |
| 16445 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 16446 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16447 | return weak_stream; |
| 16448 | } |
| 16449 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 16450 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16451 | ADD_FAILURE(); |
| 16452 | return ERR_UNEXPECTED; |
| 16453 | } |
| 16454 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16455 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16456 | ADD_FAILURE(); |
| 16457 | return LoadState(); |
| 16458 | } |
| 16459 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16460 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16461 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16462 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16463 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 16464 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16465 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16466 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16467 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16468 | const ConnectionAttempts& connection_attempts() const override { |
| 16469 | static ConnectionAttempts no_attempts; |
| 16470 | return no_attempts; |
| 16471 | } |
| 16472 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16473 | private: |
| 16474 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16475 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16476 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16477 | |
| 16478 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 16479 | }; |
| 16480 | |
| 16481 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 16482 | class FakeStreamFactory : public HttpStreamFactory { |
| 16483 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16484 | FakeStreamFactory() = default; |
| 16485 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16486 | |
| 16487 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 16488 | // RequestStream() (which may be NULL if it was destroyed already). |
| 16489 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 16490 | return last_stream_request_; |
| 16491 | } |
| 16492 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16493 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 16494 | const HttpRequestInfo& info, |
| 16495 | RequestPriority priority, |
| 16496 | const SSLConfig& server_ssl_config, |
| 16497 | const SSLConfig& proxy_ssl_config, |
| 16498 | HttpStreamRequest::Delegate* delegate, |
| 16499 | bool enable_ip_based_pooling, |
| 16500 | bool enable_alternative_services, |
| 16501 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16502 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16503 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16504 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16505 | } |
| 16506 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16507 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16508 | const HttpRequestInfo& info, |
| 16509 | RequestPriority priority, |
| 16510 | const SSLConfig& server_ssl_config, |
| 16511 | const SSLConfig& proxy_ssl_config, |
| 16512 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16513 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16514 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16515 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16516 | NOTREACHED(); |
| 16517 | return nullptr; |
| 16518 | } |
| 16519 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16520 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16521 | const HttpRequestInfo& info, |
| 16522 | RequestPriority priority, |
| 16523 | const SSLConfig& server_ssl_config, |
| 16524 | const SSLConfig& proxy_ssl_config, |
| 16525 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 16526 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16527 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16528 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16529 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16530 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16531 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16532 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16533 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16534 | } |
| 16535 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16536 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16537 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16538 | ADD_FAILURE(); |
| 16539 | } |
| 16540 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16541 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16542 | ADD_FAILURE(); |
| 16543 | return NULL; |
| 16544 | } |
| 16545 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 16546 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 16547 | const std::string& parent_absolute_name) const override { |
| 16548 | ADD_FAILURE(); |
| 16549 | } |
| 16550 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16551 | private: |
| 16552 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 16553 | |
| 16554 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 16555 | }; |
| 16556 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16557 | } // namespace |
| 16558 | |
| 16559 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16560 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16561 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16563 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16564 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16565 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16566 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16567 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16568 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16569 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16570 | request.traffic_annotation = |
| 16571 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16572 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16573 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16574 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16575 | TestCompletionCallback callback; |
| 16576 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16577 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16578 | |
| 16579 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16580 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16581 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16582 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16583 | } |
| 16584 | |
| 16585 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16586 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16587 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16589 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16590 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16591 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16592 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16593 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16594 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16595 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16596 | request.traffic_annotation = |
| 16597 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16598 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16599 | TestCompletionCallback callback; |
| 16600 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16601 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16602 | |
| 16603 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16604 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16605 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16606 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16607 | |
| 16608 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16609 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16610 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16611 | } |
| 16612 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16613 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16614 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16615 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16617 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16618 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16619 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16620 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16621 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16622 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16623 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16624 | request.traffic_annotation = |
| 16625 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16626 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16627 | TestCompletionCallback callback; |
| 16628 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16629 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16630 | |
| 16631 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16632 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16633 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16634 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16635 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16636 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16637 | |
| 16638 | trans.SetPriority(LOWEST); |
| 16639 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16640 | } |
| 16641 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16642 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16643 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16644 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16645 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16646 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16647 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16648 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16649 | |
| 16650 | // Set up SSL request. |
| 16651 | |
| 16652 | HttpRequestInfo ssl_request; |
| 16653 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16654 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16655 | ssl_request.traffic_annotation = |
| 16656 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16657 | |
| 16658 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16659 | MockWrite( |
| 16660 | "GET / HTTP/1.1\r\n" |
| 16661 | "Host: www.example.org\r\n" |
| 16662 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16663 | }; |
| 16664 | MockRead ssl_reads[] = { |
| 16665 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16666 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16667 | MockRead("hello world"), |
| 16668 | MockRead(SYNCHRONOUS, OK), |
| 16669 | }; |
| 16670 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16671 | ssl_writes, arraysize(ssl_writes)); |
| 16672 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16673 | |
| 16674 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16676 | |
| 16677 | // Set up HTTP request. |
| 16678 | |
| 16679 | HttpRequestInfo http_request; |
| 16680 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16681 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16682 | http_request.traffic_annotation = |
| 16683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16684 | |
| 16685 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16686 | MockWrite( |
| 16687 | "GET / HTTP/1.1\r\n" |
| 16688 | "Host: www.example.org\r\n" |
| 16689 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16690 | }; |
| 16691 | MockRead http_reads[] = { |
| 16692 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16693 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16694 | MockRead("falafel"), |
| 16695 | MockRead(SYNCHRONOUS, OK), |
| 16696 | }; |
| 16697 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16698 | http_writes, arraysize(http_writes)); |
| 16699 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16700 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16702 | |
| 16703 | // Start the SSL request. |
| 16704 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16705 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16706 | ASSERT_EQ(ERR_IO_PENDING, |
| 16707 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16708 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16709 | |
| 16710 | // Start the HTTP request. Pool should stall. |
| 16711 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16712 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16713 | ASSERT_EQ(ERR_IO_PENDING, |
| 16714 | http_trans.Start(&http_request, http_callback.callback(), |
| 16715 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16716 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16717 | |
| 16718 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16719 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16720 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16721 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16722 | EXPECT_EQ("hello world", response_data); |
| 16723 | |
| 16724 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16725 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16726 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16727 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16728 | |
| 16729 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16730 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16731 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16732 | EXPECT_EQ("falafel", response_data); |
| 16733 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16734 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16735 | } |
| 16736 | |
| 16737 | // Tests that when a SSL connection is established but there's no corresponding |
| 16738 | // request that needs it, the new socket is closed if the transport socket pool |
| 16739 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16740 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16741 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16742 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16743 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16744 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16745 | |
| 16746 | // Set up an ssl request. |
| 16747 | |
| 16748 | HttpRequestInfo ssl_request; |
| 16749 | ssl_request.method = "GET"; |
| 16750 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16751 | ssl_request.traffic_annotation = |
| 16752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16753 | |
| 16754 | // No data will be sent on the SSL socket. |
| 16755 | StaticSocketDataProvider ssl_data; |
| 16756 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16757 | |
| 16758 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16760 | |
| 16761 | // Set up HTTP request. |
| 16762 | |
| 16763 | HttpRequestInfo http_request; |
| 16764 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16765 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16766 | http_request.traffic_annotation = |
| 16767 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16768 | |
| 16769 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16770 | MockWrite( |
| 16771 | "GET / HTTP/1.1\r\n" |
| 16772 | "Host: www.example.org\r\n" |
| 16773 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16774 | }; |
| 16775 | MockRead http_reads[] = { |
| 16776 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16777 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16778 | MockRead("falafel"), |
| 16779 | MockRead(SYNCHRONOUS, OK), |
| 16780 | }; |
| 16781 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16782 | http_writes, arraysize(http_writes)); |
| 16783 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16786 | |
| 16787 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16788 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16789 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16790 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16791 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16792 | |
| 16793 | // Start the HTTP request. Pool should stall. |
| 16794 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16795 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16796 | ASSERT_EQ(ERR_IO_PENDING, |
| 16797 | http_trans.Start(&http_request, http_callback.callback(), |
| 16798 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16799 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16800 | |
| 16801 | // The SSL connection will automatically be closed once the connection is |
| 16802 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16803 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16804 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16805 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16806 | EXPECT_EQ("falafel", response_data); |
| 16807 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16808 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16809 | } |
| 16810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16811 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16812 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16813 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16814 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16815 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16816 | |
| 16817 | HttpRequestInfo request; |
| 16818 | request.method = "POST"; |
| 16819 | request.url = GURL("http://www.foo.com/"); |
| 16820 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16821 | request.traffic_annotation = |
| 16822 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16823 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16824 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16825 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16826 | // Send headers successfully, but get an error while sending the body. |
| 16827 | MockWrite data_writes[] = { |
| 16828 | MockWrite("POST / HTTP/1.1\r\n" |
| 16829 | "Host: www.foo.com\r\n" |
| 16830 | "Connection: keep-alive\r\n" |
| 16831 | "Content-Length: 3\r\n\r\n"), |
| 16832 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16833 | }; |
| 16834 | |
| 16835 | MockRead data_reads[] = { |
| 16836 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16837 | MockRead("hello world"), |
| 16838 | MockRead(SYNCHRONOUS, OK), |
| 16839 | }; |
| 16840 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16841 | arraysize(data_writes)); |
| 16842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16843 | |
| 16844 | TestCompletionCallback callback; |
| 16845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16846 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16848 | |
| 16849 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16850 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16852 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16853 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16854 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16855 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16856 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16857 | |
| 16858 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16859 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16861 | EXPECT_EQ("hello world", response_data); |
| 16862 | } |
| 16863 | |
| 16864 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16865 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16866 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16867 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16869 | MockWrite data_writes[] = { |
| 16870 | MockWrite("GET / HTTP/1.1\r\n" |
| 16871 | "Host: www.foo.com\r\n" |
| 16872 | "Connection: keep-alive\r\n\r\n"), |
| 16873 | MockWrite("POST / HTTP/1.1\r\n" |
| 16874 | "Host: www.foo.com\r\n" |
| 16875 | "Connection: keep-alive\r\n" |
| 16876 | "Content-Length: 3\r\n\r\n"), |
| 16877 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16878 | }; |
| 16879 | |
| 16880 | MockRead data_reads[] = { |
| 16881 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16882 | "Content-Length: 14\r\n\r\n"), |
| 16883 | MockRead("first response"), |
| 16884 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16885 | "Content-Length: 15\r\n\r\n"), |
| 16886 | MockRead("second response"), |
| 16887 | MockRead(SYNCHRONOUS, OK), |
| 16888 | }; |
| 16889 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16890 | arraysize(data_writes)); |
| 16891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16892 | |
| 16893 | TestCompletionCallback callback; |
| 16894 | HttpRequestInfo request1; |
| 16895 | request1.method = "GET"; |
| 16896 | request1.url = GURL("http://www.foo.com/"); |
| 16897 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16898 | request1.traffic_annotation = |
| 16899 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16900 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16901 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16902 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16903 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16905 | |
| 16906 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16908 | |
| 16909 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16910 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16911 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16912 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16913 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16914 | |
| 16915 | std::string response_data1; |
| 16916 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16918 | EXPECT_EQ("first response", response_data1); |
| 16919 | // Delete the transaction to release the socket back into the socket pool. |
| 16920 | trans1.reset(); |
| 16921 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16922 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16923 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16924 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16925 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16926 | |
| 16927 | HttpRequestInfo request2; |
| 16928 | request2.method = "POST"; |
| 16929 | request2.url = GURL("http://www.foo.com/"); |
| 16930 | request2.upload_data_stream = &upload_data_stream; |
| 16931 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16932 | request2.traffic_annotation = |
| 16933 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16935 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16936 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16938 | |
| 16939 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16940 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16942 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16943 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16944 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16945 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16946 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16947 | |
| 16948 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16949 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16950 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16951 | EXPECT_EQ("second response", response_data2); |
| 16952 | } |
| 16953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16954 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16955 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16956 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16957 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16958 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16959 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16960 | |
| 16961 | HttpRequestInfo request; |
| 16962 | request.method = "POST"; |
| 16963 | request.url = GURL("http://www.foo.com/"); |
| 16964 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16965 | request.traffic_annotation = |
| 16966 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16970 | // Send headers successfully, but get an error while sending the body. |
| 16971 | MockWrite data_writes[] = { |
| 16972 | MockWrite("POST / HTTP/1.1\r\n" |
| 16973 | "Host: www.foo.com\r\n" |
| 16974 | "Connection: keep-alive\r\n" |
| 16975 | "Content-Length: 3\r\n\r\n" |
| 16976 | "fo"), |
| 16977 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16978 | }; |
| 16979 | |
| 16980 | MockRead data_reads[] = { |
| 16981 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16982 | MockRead("hello world"), |
| 16983 | MockRead(SYNCHRONOUS, OK), |
| 16984 | }; |
| 16985 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16986 | arraysize(data_writes)); |
| 16987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16988 | |
| 16989 | TestCompletionCallback callback; |
| 16990 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16991 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16993 | |
| 16994 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16997 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16998 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16999 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17000 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17001 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17002 | |
| 17003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17004 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17006 | EXPECT_EQ("hello world", response_data); |
| 17007 | } |
| 17008 | |
| 17009 | // This tests the more common case than the previous test, where headers and |
| 17010 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17011 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17012 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17013 | |
| 17014 | HttpRequestInfo request; |
| 17015 | request.method = "POST"; |
| 17016 | request.url = GURL("http://www.foo.com/"); |
| 17017 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17018 | request.traffic_annotation = |
| 17019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17020 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17021 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17022 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17023 | // Send headers successfully, but get an error while sending the body. |
| 17024 | MockWrite data_writes[] = { |
| 17025 | MockWrite("POST / HTTP/1.1\r\n" |
| 17026 | "Host: www.foo.com\r\n" |
| 17027 | "Connection: keep-alive\r\n" |
| 17028 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17029 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17030 | }; |
| 17031 | |
| 17032 | MockRead data_reads[] = { |
| 17033 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17034 | MockRead("hello world"), |
| 17035 | MockRead(SYNCHRONOUS, OK), |
| 17036 | }; |
| 17037 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17038 | arraysize(data_writes)); |
| 17039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17040 | |
| 17041 | TestCompletionCallback callback; |
| 17042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17045 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17046 | // they can't be merged with the body in a single send. Not currently |
| 17047 | // necessary since a chunked body is never merged with headers, but this makes |
| 17048 | // the test more future proof. |
| 17049 | base::RunLoop().RunUntilIdle(); |
| 17050 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17051 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17052 | |
| 17053 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17054 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17056 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17057 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17058 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17059 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17060 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17061 | |
| 17062 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17063 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17064 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17065 | EXPECT_EQ("hello world", response_data); |
| 17066 | } |
| 17067 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17068 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17069 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17070 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17071 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17072 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17073 | |
| 17074 | HttpRequestInfo request; |
| 17075 | request.method = "POST"; |
| 17076 | request.url = GURL("http://www.foo.com/"); |
| 17077 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17078 | request.traffic_annotation = |
| 17079 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17080 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17082 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17083 | |
| 17084 | MockWrite data_writes[] = { |
| 17085 | MockWrite("POST / HTTP/1.1\r\n" |
| 17086 | "Host: www.foo.com\r\n" |
| 17087 | "Connection: keep-alive\r\n" |
| 17088 | "Content-Length: 3\r\n\r\n"), |
| 17089 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17090 | }; |
| 17091 | |
| 17092 | MockRead data_reads[] = { |
| 17093 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17094 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17095 | MockRead("hello world"), |
| 17096 | MockRead(SYNCHRONOUS, OK), |
| 17097 | }; |
| 17098 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17099 | arraysize(data_writes)); |
| 17100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17101 | |
| 17102 | TestCompletionCallback callback; |
| 17103 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17104 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17106 | |
| 17107 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17110 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17111 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17112 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17113 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17114 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17115 | |
| 17116 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17117 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17118 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17119 | EXPECT_EQ("hello world", response_data); |
| 17120 | } |
| 17121 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17122 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17123 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17124 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17125 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17126 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17127 | |
| 17128 | HttpRequestInfo request; |
| 17129 | request.method = "POST"; |
| 17130 | request.url = GURL("http://www.foo.com/"); |
| 17131 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17132 | request.traffic_annotation = |
| 17133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17134 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17136 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17137 | // Send headers successfully, but get an error while sending the body. |
| 17138 | MockWrite data_writes[] = { |
| 17139 | MockWrite("POST / HTTP/1.1\r\n" |
| 17140 | "Host: www.foo.com\r\n" |
| 17141 | "Connection: keep-alive\r\n" |
| 17142 | "Content-Length: 3\r\n\r\n"), |
| 17143 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17144 | }; |
| 17145 | |
| 17146 | MockRead data_reads[] = { |
| 17147 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17148 | MockRead("hello world"), |
| 17149 | MockRead(SYNCHRONOUS, OK), |
| 17150 | }; |
| 17151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17152 | arraysize(data_writes)); |
| 17153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17154 | |
| 17155 | TestCompletionCallback callback; |
| 17156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17159 | |
| 17160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17161 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17162 | } |
| 17163 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17164 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17165 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17166 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17167 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17168 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17169 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17170 | |
| 17171 | HttpRequestInfo request; |
| 17172 | request.method = "POST"; |
| 17173 | request.url = GURL("http://www.foo.com/"); |
| 17174 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17175 | request.traffic_annotation = |
| 17176 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17179 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17180 | // Send headers successfully, but get an error while sending the body. |
| 17181 | MockWrite data_writes[] = { |
| 17182 | MockWrite("POST / HTTP/1.1\r\n" |
| 17183 | "Host: www.foo.com\r\n" |
| 17184 | "Connection: keep-alive\r\n" |
| 17185 | "Content-Length: 3\r\n\r\n"), |
| 17186 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17187 | }; |
| 17188 | |
| 17189 | MockRead data_reads[] = { |
| 17190 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17191 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17192 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17193 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17194 | MockRead(SYNCHRONOUS, OK), |
| 17195 | }; |
| 17196 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17197 | arraysize(data_writes)); |
| 17198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17199 | |
| 17200 | TestCompletionCallback callback; |
| 17201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17202 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17204 | |
| 17205 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17206 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17207 | } |
| 17208 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17209 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17210 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17211 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17212 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17213 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17214 | |
| 17215 | HttpRequestInfo request; |
| 17216 | request.method = "POST"; |
| 17217 | request.url = GURL("http://www.foo.com/"); |
| 17218 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17219 | request.traffic_annotation = |
| 17220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17224 | // Send headers successfully, but get an error while sending the body. |
| 17225 | MockWrite data_writes[] = { |
| 17226 | MockWrite("POST / HTTP/1.1\r\n" |
| 17227 | "Host: www.foo.com\r\n" |
| 17228 | "Connection: keep-alive\r\n" |
| 17229 | "Content-Length: 3\r\n\r\n"), |
| 17230 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17231 | }; |
| 17232 | |
| 17233 | MockRead data_reads[] = { |
| 17234 | MockRead("HTTP 0.9 rocks!"), |
| 17235 | MockRead(SYNCHRONOUS, OK), |
| 17236 | }; |
| 17237 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17238 | arraysize(data_writes)); |
| 17239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17240 | |
| 17241 | TestCompletionCallback callback; |
| 17242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17245 | |
| 17246 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17247 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17248 | } |
| 17249 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17250 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17251 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17252 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17253 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17254 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17255 | |
| 17256 | HttpRequestInfo request; |
| 17257 | request.method = "POST"; |
| 17258 | request.url = GURL("http://www.foo.com/"); |
| 17259 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17260 | request.traffic_annotation = |
| 17261 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17262 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17264 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17265 | // Send headers successfully, but get an error while sending the body. |
| 17266 | MockWrite data_writes[] = { |
| 17267 | MockWrite("POST / HTTP/1.1\r\n" |
| 17268 | "Host: www.foo.com\r\n" |
| 17269 | "Connection: keep-alive\r\n" |
| 17270 | "Content-Length: 3\r\n\r\n"), |
| 17271 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17272 | }; |
| 17273 | |
| 17274 | MockRead data_reads[] = { |
| 17275 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17276 | MockRead(SYNCHRONOUS, OK), |
| 17277 | }; |
| 17278 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17279 | arraysize(data_writes)); |
| 17280 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17281 | |
| 17282 | TestCompletionCallback callback; |
| 17283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17286 | |
| 17287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17288 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17289 | } |
| 17290 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17291 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17292 | |
| 17293 | namespace { |
| 17294 | |
| 17295 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17296 | headers->SetHeader("Connection", "Upgrade"); |
| 17297 | headers->SetHeader("Upgrade", "websocket"); |
| 17298 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17299 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17300 | } |
| 17301 | |
| 17302 | } // namespace |
| 17303 | |
| 17304 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17305 | std::string test_cases[] = {"ws://www.example.org/", |
| 17306 | "wss://www.example.org/"}; |
| 17307 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 17308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17309 | HttpNetworkSessionPeer peer(session.get()); |
| 17310 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 17311 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
| 17312 | |
| 17313 | HttpRequestInfo request; |
| 17314 | request.method = "GET"; |
| 17315 | request.url = GURL(test_cases[i]); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17316 | request.traffic_annotation = |
| 17317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17318 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17319 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17320 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17321 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17322 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17323 | &websocket_stream_create_helper); |
| 17324 | |
| 17325 | TestCompletionCallback callback; |
| 17326 | EXPECT_EQ(ERR_IO_PENDING, |
| 17327 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 17328 | |
| 17329 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 17330 | fake_factory->last_stream_request(); |
| 17331 | ASSERT_TRUE(fake_request); |
| 17332 | EXPECT_EQ(&websocket_stream_create_helper, |
| 17333 | fake_request->websocket_stream_create_helper()); |
| 17334 | } |
| 17335 | } |
| 17336 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17337 | // Verify that proxy headers are not sent to the destination server when |
| 17338 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17339 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17340 | HttpRequestInfo request; |
| 17341 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17342 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17343 | request.traffic_annotation = |
| 17344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17345 | AddWebSocketHeaders(&request.extra_headers); |
| 17346 | |
| 17347 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17348 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17349 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17350 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17353 | |
| 17354 | // Since a proxy is configured, try to establish a tunnel. |
| 17355 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17356 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17357 | "Host: www.example.org:443\r\n" |
| 17358 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17359 | |
| 17360 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17361 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17362 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17363 | "Host: www.example.org:443\r\n" |
| 17364 | "Proxy-Connection: keep-alive\r\n" |
| 17365 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17366 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17367 | MockWrite("GET / HTTP/1.1\r\n" |
| 17368 | "Host: www.example.org\r\n" |
| 17369 | "Connection: Upgrade\r\n" |
| 17370 | "Upgrade: websocket\r\n" |
| 17371 | "Origin: http://www.example.org\r\n" |
| 17372 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17373 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17374 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17375 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17376 | |
| 17377 | // The proxy responds to the connect with a 407, using a persistent |
| 17378 | // connection. |
| 17379 | MockRead data_reads[] = { |
| 17380 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17381 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17382 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17383 | "Content-Length: 0\r\n" |
| 17384 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17385 | |
| 17386 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17387 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17388 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17389 | "Upgrade: websocket\r\n" |
| 17390 | "Connection: Upgrade\r\n" |
| 17391 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17392 | |
| 17393 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17394 | arraysize(data_writes)); |
| 17395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17396 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17397 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17398 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17399 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17400 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17401 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17402 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17403 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17404 | &websocket_stream_create_helper); |
| 17405 | |
| 17406 | { |
| 17407 | TestCompletionCallback callback; |
| 17408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17409 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17411 | |
| 17412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17413 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17414 | } |
| 17415 | |
| 17416 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17417 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17418 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17419 | EXPECT_EQ(407, response->headers->response_code()); |
| 17420 | |
| 17421 | { |
| 17422 | TestCompletionCallback callback; |
| 17423 | |
| 17424 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17425 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17427 | |
| 17428 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17429 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17430 | } |
| 17431 | |
| 17432 | response = trans->GetResponseInfo(); |
| 17433 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17434 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17435 | |
| 17436 | EXPECT_EQ(101, response->headers->response_code()); |
| 17437 | |
| 17438 | trans.reset(); |
| 17439 | session->CloseAllConnections(); |
| 17440 | } |
| 17441 | |
| 17442 | // Verify that proxy headers are not sent to the destination server when |
| 17443 | // establishing a tunnel for an insecure WebSocket connection. |
| 17444 | // This requires the authentication info to be injected into the auth cache |
| 17445 | // due to crbug.com/395064 |
| 17446 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17447 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17448 | HttpRequestInfo request; |
| 17449 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17450 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17451 | request.traffic_annotation = |
| 17452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17453 | AddWebSocketHeaders(&request.extra_headers); |
| 17454 | |
| 17455 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17456 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17457 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17458 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17459 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17460 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17461 | |
| 17462 | MockWrite data_writes[] = { |
| 17463 | // Try to establish a tunnel for the WebSocket connection, with |
| 17464 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17465 | // they cannot and will not use the same TCP/IP connection as the |
| 17466 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17467 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17468 | "Host: www.example.org:80\r\n" |
| 17469 | "Proxy-Connection: keep-alive\r\n" |
| 17470 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17471 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17472 | MockWrite("GET / HTTP/1.1\r\n" |
| 17473 | "Host: www.example.org\r\n" |
| 17474 | "Connection: Upgrade\r\n" |
| 17475 | "Upgrade: websocket\r\n" |
| 17476 | "Origin: http://www.example.org\r\n" |
| 17477 | "Sec-WebSocket-Version: 13\r\n" |
| 17478 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17479 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17480 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17481 | |
| 17482 | MockRead data_reads[] = { |
| 17483 | // HTTP CONNECT with credentials. |
| 17484 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17485 | |
| 17486 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17487 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17488 | "Upgrade: websocket\r\n" |
| 17489 | "Connection: Upgrade\r\n" |
| 17490 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17491 | |
| 17492 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17493 | arraysize(data_writes)); |
| 17494 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17495 | |
| 17496 | session->http_auth_cache()->Add( |
| 17497 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17498 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17499 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17500 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17501 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17502 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17503 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17504 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17505 | &websocket_stream_create_helper); |
| 17506 | |
| 17507 | TestCompletionCallback callback; |
| 17508 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17509 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17510 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17511 | |
| 17512 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17513 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17514 | |
| 17515 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17516 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17517 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17518 | |
| 17519 | EXPECT_EQ(101, response->headers->response_code()); |
| 17520 | |
| 17521 | trans.reset(); |
| 17522 | session->CloseAllConnections(); |
| 17523 | } |
| 17524 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17525 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17526 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17527 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17528 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17529 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17530 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17531 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17532 | |
| 17533 | HttpRequestInfo request; |
| 17534 | request.method = "POST"; |
| 17535 | request.url = GURL("http://www.foo.com/"); |
| 17536 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17537 | request.traffic_annotation = |
| 17538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17541 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17542 | MockWrite data_writes[] = { |
| 17543 | MockWrite("POST / HTTP/1.1\r\n" |
| 17544 | "Host: www.foo.com\r\n" |
| 17545 | "Connection: keep-alive\r\n" |
| 17546 | "Content-Length: 3\r\n\r\n"), |
| 17547 | MockWrite("foo"), |
| 17548 | }; |
| 17549 | |
| 17550 | MockRead data_reads[] = { |
| 17551 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17552 | MockRead(SYNCHRONOUS, OK), |
| 17553 | }; |
| 17554 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17555 | arraysize(data_writes)); |
| 17556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17557 | |
| 17558 | TestCompletionCallback callback; |
| 17559 | |
| 17560 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17561 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17562 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17563 | |
| 17564 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17565 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17566 | |
| 17567 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17568 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17569 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17570 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17571 | } |
| 17572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17573 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17574 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17575 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17576 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17577 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17578 | |
| 17579 | HttpRequestInfo request; |
| 17580 | request.method = "POST"; |
| 17581 | request.url = GURL("http://www.foo.com/"); |
| 17582 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17583 | request.traffic_annotation = |
| 17584 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17585 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17588 | MockWrite data_writes[] = { |
| 17589 | MockWrite("POST / HTTP/1.1\r\n" |
| 17590 | "Host: www.foo.com\r\n" |
| 17591 | "Connection: keep-alive\r\n" |
| 17592 | "Content-Length: 3\r\n\r\n"), |
| 17593 | MockWrite("foo"), |
| 17594 | }; |
| 17595 | |
| 17596 | MockRead data_reads[] = { |
| 17597 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17598 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17599 | MockRead(SYNCHRONOUS, OK), |
| 17600 | }; |
| 17601 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17602 | arraysize(data_writes)); |
| 17603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17604 | |
| 17605 | TestCompletionCallback callback; |
| 17606 | |
| 17607 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17608 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17609 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17610 | |
| 17611 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17612 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17613 | |
| 17614 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17615 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17616 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17617 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17618 | } |
| 17619 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17620 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17621 | ChunkedUploadDataStream upload_data_stream(0); |
| 17622 | |
| 17623 | HttpRequestInfo request; |
| 17624 | request.method = "POST"; |
| 17625 | request.url = GURL("http://www.foo.com/"); |
| 17626 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17627 | request.traffic_annotation = |
| 17628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17629 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17630 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17631 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17632 | // Send headers successfully, but get an error while sending the body. |
| 17633 | MockWrite data_writes[] = { |
| 17634 | MockWrite("POST / HTTP/1.1\r\n" |
| 17635 | "Host: www.foo.com\r\n" |
| 17636 | "Connection: keep-alive\r\n" |
| 17637 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17638 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17639 | }; |
| 17640 | |
| 17641 | MockRead data_reads[] = { |
| 17642 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17643 | MockRead(SYNCHRONOUS, OK), |
| 17644 | }; |
| 17645 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17646 | arraysize(data_writes)); |
| 17647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17648 | |
| 17649 | TestCompletionCallback callback; |
| 17650 | |
| 17651 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17652 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17653 | |
| 17654 | base::RunLoop().RunUntilIdle(); |
| 17655 | upload_data_stream.AppendData("f", 1, false); |
| 17656 | |
| 17657 | base::RunLoop().RunUntilIdle(); |
| 17658 | upload_data_stream.AppendData("oo", 2, true); |
| 17659 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17660 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17661 | |
| 17662 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17663 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17664 | |
| 17665 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17666 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17667 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17668 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17669 | } |
| 17670 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17671 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17672 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17673 | const std::string https_url = "https://www.example.com"; |
| 17674 | HttpRequestInfo request; |
| 17675 | request.url = GURL(https_url); |
| 17676 | request.method = "GET"; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17677 | request.traffic_annotation = |
| 17678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17679 | |
| 17680 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17681 | ssl.ssl_info.token_binding_negotiated = true; |
| 17682 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17683 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17685 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17686 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17687 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17688 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17689 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17690 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17692 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17693 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17695 | |
| 17696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17697 | TestCompletionCallback callback; |
| 17698 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17699 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17700 | |
| 17701 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17702 | |
| 17703 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17704 | HttpRequestHeaders headers; |
| 17705 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17706 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17707 | } |
| 17708 | #endif // !defined(OS_IOS) |
| 17709 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17710 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17711 | const std::string& accept_encoding, |
| 17712 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17713 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17714 | bool should_match) { |
| 17715 | HttpRequestInfo request; |
| 17716 | request.method = "GET"; |
| 17717 | request.url = GURL("http://www.foo.com/"); |
| 17718 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17719 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17720 | request.traffic_annotation = |
| 17721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17722 | |
| 17723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17725 | // Send headers successfully, but get an error while sending the body. |
| 17726 | MockWrite data_writes[] = { |
| 17727 | MockWrite("GET / HTTP/1.1\r\n" |
| 17728 | "Host: www.foo.com\r\n" |
| 17729 | "Connection: keep-alive\r\n" |
| 17730 | "Accept-Encoding: "), |
| 17731 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17732 | }; |
| 17733 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17734 | std::string response_code = "200 OK"; |
| 17735 | std::string extra; |
| 17736 | if (!location.empty()) { |
| 17737 | response_code = "301 Redirect\r\nLocation: "; |
| 17738 | response_code.append(location); |
| 17739 | } |
| 17740 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17741 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17742 | MockRead("HTTP/1.0 "), |
| 17743 | MockRead(response_code.data()), |
| 17744 | MockRead("\r\nContent-Encoding: "), |
| 17745 | MockRead(content_encoding.data()), |
| 17746 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17747 | MockRead(SYNCHRONOUS, OK), |
| 17748 | }; |
| 17749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17750 | arraysize(data_writes)); |
| 17751 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17752 | |
| 17753 | TestCompletionCallback callback; |
| 17754 | |
| 17755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17757 | |
| 17758 | rv = callback.WaitForResult(); |
| 17759 | if (should_match) { |
| 17760 | EXPECT_THAT(rv, IsOk()); |
| 17761 | } else { |
| 17762 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17763 | } |
| 17764 | } |
| 17765 | |
| 17766 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17767 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17768 | } |
| 17769 | |
| 17770 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17771 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17772 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17773 | } |
| 17774 | |
| 17775 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17776 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17777 | "", false); |
| 17778 | } |
| 17779 | |
| 17780 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17781 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17782 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17783 | } |
| 17784 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17785 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17786 | ProxyConfig proxy_config; |
| 17787 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17788 | proxy_config.set_pac_mandatory(true); |
| 17789 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17790 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17791 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17792 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17793 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17794 | |
| 17795 | HttpRequestInfo request; |
| 17796 | request.method = "GET"; |
| 17797 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17798 | request.traffic_annotation = |
| 17799 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17800 | |
| 17801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17803 | |
| 17804 | TestCompletionCallback callback; |
| 17805 | |
| 17806 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17808 | EXPECT_THAT(callback.WaitForResult(), |
| 17809 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17810 | } |
| 17811 | |
| 17812 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17813 | ProxyConfig proxy_config; |
| 17814 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17815 | proxy_config.set_pac_mandatory(true); |
| 17816 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17817 | new MockAsyncProxyResolverFactory(false); |
| 17818 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17819 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17820 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17821 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17822 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17823 | HttpRequestInfo request; |
| 17824 | request.method = "GET"; |
| 17825 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17826 | request.traffic_annotation = |
| 17827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17828 | |
| 17829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17831 | |
| 17832 | TestCompletionCallback callback; |
| 17833 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17835 | |
| 17836 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17837 | ERR_FAILED, &resolver); |
| 17838 | EXPECT_THAT(callback.WaitForResult(), |
| 17839 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17840 | } |
| 17841 | |
| 17842 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17843 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17844 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17845 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17846 | session_deps_.enable_quic = false; |
| 17847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17848 | |
| 17849 | HttpRequestInfo request; |
| 17850 | request.method = "GET"; |
| 17851 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17852 | request.traffic_annotation = |
| 17853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17854 | |
| 17855 | TestCompletionCallback callback; |
| 17856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17857 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17859 | |
| 17860 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17861 | } |
| 17862 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17863 | } // namespace net |