[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" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 40 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 42 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 43 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 44 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 45 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 46 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 47 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 48 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 49 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 50 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 51 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 52 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 56 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 57 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 58 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 59 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 60 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 61 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 62 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 63 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 64 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 65 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 66 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 67 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 68 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 69 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 70 | #include "net/log/test_net_log_entry.h" |
| 71 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 72 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 73 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 74 | #include "net/proxy_resolution/proxy_info.h" |
| 75 | #include "net/proxy_resolution/proxy_resolver.h" |
| 76 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
| 77 | #include "net/proxy_resolution/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 84 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 85 | #include "net/socket/socket_test_util.h" |
| 86 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 87 | #include "net/spdy/chromium/spdy_session.h" |
| 88 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 89 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 90 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 91 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 92 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 94 | #include "net/ssl/ssl_config_service_defaults.h" |
| 95 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 96 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 97 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 98 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 99 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 100 | #include "net/test/test_data_directory.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 101 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 102 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 103 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 104 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 106 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 107 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 108 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 109 | #if defined(NTLM_PORTABLE) |
| 110 | #include "base/base64.h" |
| 111 | #include "net/ntlm/ntlm_test_data.h" |
| 112 | #endif |
| 113 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 114 | using net::test::IsError; |
| 115 | using net::test::IsOk; |
| 116 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 117 | using base::ASCIIToUTF16; |
| 118 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 119 | //----------------------------------------------------------------------------- |
| 120 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 121 | namespace net { |
| 122 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 123 | namespace { |
| 124 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 125 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 126 | public: |
| 127 | TestNetworkStreamThrottler() |
| 128 | : throttle_new_requests_(false), |
| 129 | num_set_priority_calls_(0), |
| 130 | last_priority_set_(IDLE) {} |
| 131 | |
| 132 | ~TestNetworkStreamThrottler() override { |
| 133 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 134 | } |
| 135 | |
| 136 | // NetworkThrottleManager |
| 137 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 138 | RequestPriority priority, |
| 139 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 140 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 141 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 142 | outstanding_throttles_.insert(test_throttle.get()); |
| 143 | return std::move(test_throttle); |
| 144 | } |
| 145 | |
| 146 | void UnthrottleAllRequests() { |
| 147 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 148 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 149 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 150 | throttle->Unthrottle(); |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 155 | throttle_new_requests_ = throttle_new_requests; |
| 156 | } |
| 157 | |
| 158 | // Includes both throttled and unthrottled throttles. |
| 159 | size_t num_outstanding_requests() const { |
| 160 | return outstanding_throttles_.size(); |
| 161 | } |
| 162 | |
| 163 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 164 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 165 | void set_priority_change_closure( |
| 166 | const base::Closure& priority_change_closure) { |
| 167 | priority_change_closure_ = priority_change_closure; |
| 168 | } |
| 169 | |
| 170 | private: |
| 171 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 172 | public: |
| 173 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 174 | |
| 175 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 176 | bool IsBlocked() const override { return throttled_; } |
| 177 | RequestPriority Priority() const override { |
| 178 | NOTREACHED(); |
| 179 | return IDLE; |
| 180 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 181 | void SetPriority(RequestPriority priority) override { |
| 182 | throttler_->SetPriorityCalled(priority); |
| 183 | } |
| 184 | |
| 185 | TestThrottle(bool throttled, |
| 186 | ThrottleDelegate* delegate, |
| 187 | TestNetworkStreamThrottler* throttler) |
| 188 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 189 | |
| 190 | void Unthrottle() { |
| 191 | EXPECT_TRUE(throttled_); |
| 192 | |
| 193 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 194 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | bool throttled_; |
| 198 | ThrottleDelegate* delegate_; |
| 199 | TestNetworkStreamThrottler* throttler_; |
| 200 | }; |
| 201 | |
| 202 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 203 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 204 | outstanding_throttles_.erase(throttle); |
| 205 | } |
| 206 | |
| 207 | void SetPriorityCalled(RequestPriority priority) { |
| 208 | ++num_set_priority_calls_; |
| 209 | last_priority_set_ = priority; |
| 210 | if (!priority_change_closure_.is_null()) |
| 211 | priority_change_closure_.Run(); |
| 212 | } |
| 213 | |
| 214 | // Includes both throttled and unthrottled throttles. |
| 215 | std::set<TestThrottle*> outstanding_throttles_; |
| 216 | bool throttle_new_requests_; |
| 217 | int num_set_priority_calls_; |
| 218 | RequestPriority last_priority_set_; |
| 219 | base::Closure priority_change_closure_; |
| 220 | |
| 221 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 222 | }; |
| 223 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 224 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 225 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 226 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 227 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 228 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 229 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 230 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 231 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 232 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 233 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 234 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 235 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 236 | const char kAlternativeServiceHttpHeader[] = |
| 237 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 238 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 239 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 240 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 241 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 242 | } |
| 243 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 244 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 245 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 246 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 247 | } |
| 248 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 249 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 250 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 251 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 254 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 255 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 256 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 257 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 258 | if (!params) |
| 259 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 260 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 261 | if (!params->GetList("headers", &header_list)) |
| 262 | return false; |
| 263 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 264 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 265 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 266 | return true; |
| 267 | } |
| 268 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 270 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 271 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 273 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 275 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 276 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 277 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 278 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 279 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 280 | |
| 281 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 283 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 284 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 285 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 286 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 287 | } |
| 288 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 289 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 290 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 291 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 292 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 294 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 295 | |
| 296 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 297 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 298 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 299 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 300 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 301 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 302 | load_timing_info.send_start); |
| 303 | |
| 304 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 305 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 306 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 308 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 309 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 313 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 314 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 315 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 316 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 317 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 318 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 319 | |
| 320 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 321 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 322 | load_timing_info.proxy_resolve_end); |
| 323 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 324 | load_timing_info.send_start); |
| 325 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 326 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 327 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 328 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 329 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 330 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 334 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 335 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 336 | int connect_timing_flags) { |
| 337 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 338 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 339 | |
| 340 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 341 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 342 | load_timing_info.proxy_resolve_end); |
| 343 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 344 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 345 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 346 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 347 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 348 | load_timing_info.send_start); |
| 349 | |
| 350 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 351 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 352 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 353 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 354 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 355 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 356 | } |
| 357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 358 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 359 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 360 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 361 | } |
| 362 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 363 | // Note that the pointer written into |*throttler| will only be valid |
| 364 | // for the lifetime of the returned HttpNetworkSession. |
| 365 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 366 | SpdySessionDependencies* session_deps, |
| 367 | TestNetworkStreamThrottler** throttler) { |
| 368 | std::unique_ptr<HttpNetworkSession> session( |
| 369 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 370 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 371 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 372 | *throttler = owned_throttler.get(); |
| 373 | |
| 374 | HttpNetworkSessionPeer peer(session.get()); |
| 375 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 376 | |
| 377 | return session; |
| 378 | } |
| 379 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 380 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 381 | public: |
| 382 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 383 | |
| 384 | // ProxyResolverFactory override. |
| 385 | int CreateProxyResolver( |
| 386 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 387 | std::unique_ptr<ProxyResolver>* result, |
| 388 | const CompletionCallback& callback, |
| 389 | std::unique_ptr<Request>* request) override { |
| 390 | return ERR_PAC_SCRIPT_FAILED; |
| 391 | } |
| 392 | }; |
| 393 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 394 | } // namespace |
| 395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 396 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 397 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 398 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 399 | // Important to restore the per-pool limit first, since the pool limit must |
| 400 | // always be greater than group limit, and the tests reduce both limits. |
| 401 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 402 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 403 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 404 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 405 | } |
| 406 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 407 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 408 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 409 | : ssl_(ASYNC, OK), |
| 410 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 411 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 412 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 413 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 414 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 415 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 416 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 417 | struct SimpleGetHelperResult { |
| 418 | int rv; |
| 419 | std::string status_line; |
| 420 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 421 | int64_t total_received_bytes; |
| 422 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 423 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 424 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 425 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 426 | }; |
| 427 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 428 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 429 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 431 | } |
| 432 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 433 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 434 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 435 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 436 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 437 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 438 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 439 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 440 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 441 | } |
| 442 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 443 | // Either |write_failure| specifies a write failure or |read_failure| |
| 444 | // specifies a read failure when using a reused socket. In either case, the |
| 445 | // failure should cause the network transaction to resend the request, and the |
| 446 | // other argument should be NULL. |
| 447 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 448 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 449 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 450 | // Either |write_failure| specifies a write failure or |read_failure| |
| 451 | // specifies a read failure when using a reused socket. In either case, the |
| 452 | // failure should cause the network transaction to resend the request, and the |
| 453 | // other argument should be NULL. |
| 454 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 455 | const MockRead* read_failure, |
| 456 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 457 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 458 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 459 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 462 | HttpRequestInfo request; |
| 463 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 464 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 465 | request.traffic_annotation = |
| 466 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 467 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 468 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 469 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 472 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 473 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 474 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 475 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 477 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 478 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 479 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 480 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 482 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 483 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 484 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 485 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 486 | |
| 487 | // Even in the failure cases that use this function, connections are always |
| 488 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 489 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 490 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 491 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 492 | if (out.rv != OK) |
| 493 | return out; |
| 494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 495 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 496 | // Can't use ASSERT_* inside helper functions like this, so |
| 497 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 498 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 499 | out.rv = ERR_UNEXPECTED; |
| 500 | return out; |
| 501 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 502 | out.status_line = response->headers->GetStatusLine(); |
| 503 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 504 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 505 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 506 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 507 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 509 | EXPECT_EQ(got_endpoint, |
| 510 | out.remote_endpoint_after_start.address().size() > 0); |
| 511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 513 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 514 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 515 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 516 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 517 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 518 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 519 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 520 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 521 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 522 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 523 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 524 | std::string line; |
| 525 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 526 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 527 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 528 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 529 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 530 | std::string value; |
| 531 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 532 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 533 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 534 | EXPECT_EQ("keep-alive", value); |
| 535 | |
| 536 | std::string response_headers; |
| 537 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 538 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 539 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 541 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 542 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 543 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 545 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 546 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 547 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 548 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 549 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 550 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 551 | MockWrite data_writes[] = { |
| 552 | MockWrite("GET / HTTP/1.1\r\n" |
| 553 | "Host: www.example.org\r\n" |
| 554 | "Connection: keep-alive\r\n\r\n"), |
| 555 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 556 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 557 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 558 | arraysize(data_writes)); |
| 559 | StaticSocketDataProvider* data[] = {&reads}; |
| 560 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 561 | |
| 562 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 563 | out.total_sent_bytes); |
| 564 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 565 | } |
| 566 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 567 | void AddSSLSocketData() { |
| 568 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 569 | ssl_.ssl_info.cert = |
| 570 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 571 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 573 | } |
| 574 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 575 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 576 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 577 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 578 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 579 | |
| 580 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 581 | |
| 582 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 583 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 584 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 585 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 586 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 587 | |
| 588 | // Original socket limits. Some tests set these. Safest to always restore |
| 589 | // them once each test has been run. |
| 590 | int old_max_group_sockets_; |
| 591 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 592 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 593 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 594 | namespace { |
| 595 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 597 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | BeforeHeadersSentHandler() |
| 599 | : observed_before_headers_sent_with_proxy_(false), |
| 600 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 602 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 603 | HttpRequestHeaders* request_headers) { |
| 604 | observed_before_headers_sent_ = true; |
| 605 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 606 | !proxy_info.is_quic()) { |
| 607 | return; |
| 608 | } |
| 609 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 610 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 611 | } |
| 612 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 613 | bool observed_before_headers_sent_with_proxy() const { |
| 614 | return observed_before_headers_sent_with_proxy_; |
| 615 | } |
| 616 | |
| 617 | bool observed_before_headers_sent() const { |
| 618 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | std::string observed_proxy_server_uri() const { |
| 622 | return observed_proxy_server_uri_; |
| 623 | } |
| 624 | |
| 625 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 626 | bool observed_before_headers_sent_with_proxy_; |
| 627 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 628 | std::string observed_proxy_server_uri_; |
| 629 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 630 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 631 | }; |
| 632 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 633 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 634 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 635 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 636 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 637 | const int sizeof_row = strlen(row); |
| 638 | const int num_rows = static_cast<int>( |
| 639 | ceil(static_cast<float>(size) / sizeof_row)); |
| 640 | const int sizeof_data = num_rows * sizeof_row; |
| 641 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 642 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 643 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 644 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 645 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 646 | } |
| 647 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 648 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 649 | uint64_t MockGetMSTime() { |
| 650 | // Tue, 23 May 2017 20:13:07 +0000 |
| 651 | return 131400439870000000; |
| 652 | } |
| 653 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 654 | // Alternative functions that eliminate randomness and dependency on the local |
| 655 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 656 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 657 | // This is set to 0xaa because the client challenge for testing in |
| 658 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 659 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 662 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 663 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 664 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 665 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 666 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 667 | template<typename ParentPool> |
| 668 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 669 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 670 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 671 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 672 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 673 | const std::string last_group_name_received() const { |
| 674 | return last_group_name_; |
| 675 | } |
| 676 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 677 | bool socket_requested() const { return socket_requested_; } |
| 678 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | int RequestSocket(const std::string& group_name, |
| 680 | const void* socket_params, |
| 681 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 682 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 683 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 684 | ClientSocketHandle* handle, |
| 685 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 686 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 687 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 688 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 689 | return ERR_IO_PENDING; |
| 690 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 691 | void CancelRequest(const std::string& group_name, |
| 692 | ClientSocketHandle* handle) override {} |
| 693 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 694 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 695 | int id) override {} |
| 696 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 697 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 698 | int IdleSocketCount() const override { return 0; } |
| 699 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 700 | return 0; |
| 701 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 702 | LoadState GetLoadState(const std::string& group_name, |
| 703 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 704 | return LOAD_STATE_IDLE; |
| 705 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 706 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 707 | return base::TimeDelta(); |
| 708 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 709 | |
| 710 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 711 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 712 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 713 | }; |
| 714 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 715 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 716 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 717 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 718 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 719 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 720 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 721 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 722 | CaptureGroupNameSSLSocketPool; |
| 723 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 724 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 725 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 726 | HostResolver* host_resolver, |
| 727 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 728 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 729 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 730 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 731 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 732 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 733 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 734 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 735 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 736 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 737 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 738 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 739 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 740 | : SSLClientSocketPool(0, |
| 741 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 742 | cert_verifier, |
| 743 | NULL, |
| 744 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 745 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 746 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 747 | std::string(), |
| 748 | NULL, |
| 749 | NULL, |
| 750 | NULL, |
| 751 | NULL, |
| 752 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 753 | NULL) { |
| 754 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 755 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 756 | //----------------------------------------------------------------------------- |
| 757 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 758 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 759 | // configured for common cases. |
| 760 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 761 | if (!auth_challenge) |
| 762 | return false; |
| 763 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 764 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 765 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 766 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 767 | return true; |
| 768 | } |
| 769 | |
| 770 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 771 | if (!auth_challenge) |
| 772 | return false; |
| 773 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 774 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 775 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 776 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 777 | return true; |
| 778 | } |
| 779 | |
| 780 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 781 | if (!auth_challenge) |
| 782 | return false; |
| 783 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 784 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 785 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 786 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 787 | return true; |
| 788 | } |
| 789 | |
| 790 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 791 | if (!auth_challenge) |
| 792 | return false; |
| 793 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 794 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 795 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 796 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 797 | return true; |
| 798 | } |
| 799 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 800 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 801 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 802 | if (!auth_challenge) |
| 803 | return false; |
| 804 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 805 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 806 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 807 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 808 | return true; |
| 809 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 810 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 811 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 812 | } // namespace |
| 813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 814 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | } |
| 818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 819 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 820 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 821 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 822 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 823 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 824 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 825 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 826 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 827 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 828 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 829 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 830 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 831 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 832 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 833 | |
| 834 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 838 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 839 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 840 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 841 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 843 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 844 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 845 | EXPECT_THAT(out.rv, IsOk()); |
| 846 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 847 | EXPECT_EQ("hello world", out.response_data); |
| 848 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 849 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 850 | } |
| 851 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 852 | // Response with no status line, and a weird port. Should fail by default. |
| 853 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 854 | MockRead data_reads[] = { |
| 855 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 856 | }; |
| 857 | |
| 858 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 859 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 860 | |
| 861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 862 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 863 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 864 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 865 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 866 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 867 | request.method = "GET"; |
| 868 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 869 | request.traffic_annotation = |
| 870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 871 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 872 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 873 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 874 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 875 | } |
| 876 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 877 | // Tests that request info can be destroyed after the headers phase is complete. |
| 878 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 880 | auto trans = |
| 881 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 882 | |
| 883 | MockRead data_reads[] = { |
| 884 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 885 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 886 | }; |
| 887 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 888 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 889 | |
| 890 | TestCompletionCallback callback; |
| 891 | |
| 892 | { |
| 893 | auto request = std::make_unique<HttpRequestInfo>(); |
| 894 | request->method = "GET"; |
| 895 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 896 | request->traffic_annotation = |
| 897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 898 | |
| 899 | int rv = |
| 900 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 901 | |
| 902 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 903 | } // Let request info be destroyed. |
| 904 | |
| 905 | trans.reset(); |
| 906 | } |
| 907 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 908 | // Response with no status line, and a weird port. Option to allow weird ports |
| 909 | // enabled. |
| 910 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 911 | MockRead data_reads[] = { |
| 912 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 913 | }; |
| 914 | |
| 915 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 916 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 917 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 919 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 920 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 921 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 922 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 923 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 924 | request.method = "GET"; |
| 925 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 926 | request.traffic_annotation = |
| 927 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 928 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 929 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 930 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 931 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 932 | |
| 933 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 934 | ASSERT_TRUE(info->headers); |
| 935 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 936 | |
| 937 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 938 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 939 | } |
| 940 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 942 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 943 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 944 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 946 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 947 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 948 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 949 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 951 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 952 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 953 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 957 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 959 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 960 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 961 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 963 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 964 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 965 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 966 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 967 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 968 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 972 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 973 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 974 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 975 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 976 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 977 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 978 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 979 | EXPECT_THAT(out.rv, IsOk()); |
| 980 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 981 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 982 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 983 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 987 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 988 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 989 | MockRead("\n"), |
| 990 | MockRead("\n"), |
| 991 | MockRead("Q"), |
| 992 | MockRead("J"), |
| 993 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 994 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 995 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 996 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 997 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 998 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 999 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 1000 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1001 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1002 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1006 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1007 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1008 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1009 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1010 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1011 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1012 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1013 | EXPECT_THAT(out.rv, IsOk()); |
| 1014 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1015 | EXPECT_EQ("HTT", out.response_data); |
| 1016 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1017 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1020 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1021 | // persistent connection. The response should still terminate since a 204 |
| 1022 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1023 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1024 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1025 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1026 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1027 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1028 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1029 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1030 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1031 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1032 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1033 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1034 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1035 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1036 | int64_t response_size = reads_size - strlen(junk); |
| 1037 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1038 | } |
| 1039 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1040 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1041 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1042 | std::string final_chunk = "0\r\n\r\n"; |
| 1043 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1044 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1045 | MockRead data_reads[] = { |
| 1046 | MockRead("HTTP/1.1 200 OK\r\nTransfer-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"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1051 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1052 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1053 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 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] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1057 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1058 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1059 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1060 | int64_t response_size = reads_size - extra_data.size(); |
| 1061 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1062 | } |
| 1063 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1064 | // Next tests deal with http://crbug.com/56344. |
| 1065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1066 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1067 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1068 | MockRead data_reads[] = { |
| 1069 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1070 | MockRead("Content-Length: 10\r\n"), |
| 1071 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1072 | }; |
| 1073 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1074 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1075 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1076 | } |
| 1077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1078 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1079 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1080 | MockRead data_reads[] = { |
| 1081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n"), |
| 1083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1084 | MockRead("Hello"), |
| 1085 | }; |
| 1086 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1087 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1088 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1089 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1090 | EXPECT_EQ("Hello", out.response_data); |
| 1091 | } |
| 1092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1093 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1094 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1095 | // More than 2 dupes. |
| 1096 | { |
| 1097 | MockRead data_reads[] = { |
| 1098 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1099 | MockRead("Content-Length: 5\r\n"), |
| 1100 | MockRead("Content-Length: 5\r\n"), |
| 1101 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1102 | MockRead("Hello"), |
| 1103 | }; |
| 1104 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1105 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1106 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1107 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1108 | EXPECT_EQ("Hello", out.response_data); |
| 1109 | } |
| 1110 | // HTTP/1.0 |
| 1111 | { |
| 1112 | MockRead data_reads[] = { |
| 1113 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1114 | MockRead("Content-Length: 5\r\n"), |
| 1115 | MockRead("Content-Length: 5\r\n"), |
| 1116 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1117 | MockRead("Hello"), |
| 1118 | }; |
| 1119 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1120 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1122 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1123 | EXPECT_EQ("Hello", out.response_data); |
| 1124 | } |
| 1125 | // 2 dupes and one mismatched. |
| 1126 | { |
| 1127 | MockRead data_reads[] = { |
| 1128 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1129 | MockRead("Content-Length: 10\r\n"), |
| 1130 | MockRead("Content-Length: 10\r\n"), |
| 1131 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1132 | }; |
| 1133 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1134 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1135 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1136 | } |
| 1137 | } |
| 1138 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1139 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1140 | MultipleContentLengthHeadersTransferEncoding) { |
| 1141 | MockRead data_reads[] = { |
| 1142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1143 | MockRead("Content-Length: 666\r\n"), |
| 1144 | MockRead("Content-Length: 1337\r\n"), |
| 1145 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1146 | MockRead("5\r\nHello\r\n"), |
| 1147 | MockRead("1\r\n"), |
| 1148 | MockRead(" \r\n"), |
| 1149 | MockRead("5\r\nworld\r\n"), |
| 1150 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1151 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1152 | }; |
| 1153 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1154 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1155 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1156 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1157 | EXPECT_EQ("Hello world", out.response_data); |
| 1158 | } |
| 1159 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1160 | // Next tests deal with http://crbug.com/98895. |
| 1161 | |
| 1162 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1163 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1164 | MockRead data_reads[] = { |
| 1165 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1166 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1167 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1168 | MockRead("Hello"), |
| 1169 | }; |
| 1170 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1171 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1172 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1173 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1174 | EXPECT_EQ("Hello", out.response_data); |
| 1175 | } |
| 1176 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1177 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1178 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | MockRead data_reads[] = { |
| 1180 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1181 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1182 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1183 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1184 | MockRead("Hello"), |
| 1185 | }; |
| 1186 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1187 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1188 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1189 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1190 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1194 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | MockRead data_reads[] = { |
| 1196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1197 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1198 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1199 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1200 | MockRead("Hello"), |
| 1201 | }; |
| 1202 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1203 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1204 | EXPECT_THAT(out.rv, |
| 1205 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | } |
| 1207 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1208 | // Checks that two identical Location headers result in no error. |
| 1209 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1210 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | MockRead data_reads[] = { |
| 1212 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1213 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1214 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1215 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1216 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1217 | }; |
| 1218 | |
| 1219 | HttpRequestInfo request; |
| 1220 | request.method = "GET"; |
| 1221 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1222 | request.traffic_annotation = |
| 1223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1227 | |
| 1228 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1231 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1232 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1233 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1235 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1236 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1238 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1239 | ASSERT_TRUE(response); |
| 1240 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1241 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1242 | std::string url; |
| 1243 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1244 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1245 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1246 | } |
| 1247 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1248 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1249 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1250 | MockRead data_reads[] = { |
| 1251 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1252 | MockRead("Location: http://good.com/\r\n"), |
| 1253 | MockRead("Location: http://evil.com/\r\n"), |
| 1254 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1255 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1256 | }; |
| 1257 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1258 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1259 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1260 | } |
| 1261 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1263 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1264 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1265 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1267 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1268 | request.traffic_annotation = |
| 1269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1270 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1273 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1274 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1275 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1276 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1277 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1278 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1279 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1280 | "Host: www.example.org\r\n" |
| 1281 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1282 | }; |
| 1283 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1284 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1285 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1286 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1287 | // No response body because the test stops reading here. |
| 1288 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1289 | }; |
| 1290 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1291 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1292 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1293 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1294 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1295 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1297 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1299 | |
| 1300 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1304 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1305 | |
| 1306 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1307 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1308 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1309 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1310 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1311 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1312 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1313 | |
| 1314 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1315 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1316 | bool has_server_header = response->headers->EnumerateHeader( |
| 1317 | &iter, "Server", &server_header); |
| 1318 | EXPECT_TRUE(has_server_header); |
| 1319 | EXPECT_EQ("Blah", server_header); |
| 1320 | |
| 1321 | // Reading should give EOF right away, since there is no message body |
| 1322 | // (despite non-zero content-length). |
| 1323 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1324 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1326 | EXPECT_EQ("", response_data); |
| 1327 | } |
| 1328 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1329 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1330 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1331 | |
| 1332 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1333 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1334 | MockRead("hello"), |
| 1335 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1336 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1337 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1340 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1342 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | "hello", "world" |
| 1344 | }; |
| 1345 | |
| 1346 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1347 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1349 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1350 | request.traffic_annotation = |
| 1351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1355 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1357 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | |
| 1360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1361 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1363 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1364 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1366 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1367 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1368 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
| 1370 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1371 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1373 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1374 | } |
| 1375 | } |
| 1376 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1377 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1378 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1379 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1380 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1381 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1382 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1383 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1384 | request.method = "POST"; |
| 1385 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1386 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1387 | request.traffic_annotation = |
| 1388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1389 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1390 | // Check the upload progress returned before initialization is correct. |
| 1391 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1392 | EXPECT_EQ(0u, progress.size()); |
| 1393 | EXPECT_EQ(0u, progress.position()); |
| 1394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1396 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1397 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1398 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1399 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1400 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1401 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1402 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1404 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1407 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1409 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1411 | |
| 1412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1413 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1416 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1417 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1418 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1419 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1420 | |
| 1421 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1422 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1424 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1425 | } |
| 1426 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1427 | // This test is almost the same as Ignores100 above, but the response contains |
| 1428 | // 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] | 1429 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1430 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1431 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1432 | request.method = "GET"; |
| 1433 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1434 | request.traffic_annotation = |
| 1435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1436 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1439 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1440 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1441 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1442 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1443 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1445 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1446 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1447 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1449 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1450 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1451 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1452 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1453 | |
| 1454 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1455 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1456 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1457 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1458 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1459 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1460 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1461 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1462 | |
| 1463 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1464 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1465 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1466 | EXPECT_EQ("hello world", response_data); |
| 1467 | } |
| 1468 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1469 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1470 | HttpRequestInfo request; |
| 1471 | request.method = "POST"; |
| 1472 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1473 | request.traffic_annotation = |
| 1474 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1475 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1478 | |
| 1479 | MockRead data_reads[] = { |
| 1480 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1481 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1482 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1483 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1484 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1485 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1486 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1490 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1493 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1494 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1495 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1496 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1497 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1498 | } |
| 1499 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1500 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1501 | HttpRequestInfo request; |
| 1502 | request.method = "POST"; |
| 1503 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1504 | request.traffic_annotation = |
| 1505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1509 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1510 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1511 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1512 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1513 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1514 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1516 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1517 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1518 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1520 | |
| 1521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1522 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1523 | } |
| 1524 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1525 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1526 | const MockWrite* write_failure, |
| 1527 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1528 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1529 | request.method = "GET"; |
| 1530 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1531 | request.traffic_annotation = |
| 1532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1533 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1534 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1535 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1537 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1538 | // Written data for successfully sending both requests. |
| 1539 | MockWrite data1_writes[] = { |
| 1540 | MockWrite("GET / HTTP/1.1\r\n" |
| 1541 | "Host: www.foo.com\r\n" |
| 1542 | "Connection: keep-alive\r\n\r\n"), |
| 1543 | MockWrite("GET / HTTP/1.1\r\n" |
| 1544 | "Host: www.foo.com\r\n" |
| 1545 | "Connection: keep-alive\r\n\r\n") |
| 1546 | }; |
| 1547 | |
| 1548 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1549 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1550 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1551 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1552 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1553 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1554 | |
| 1555 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1556 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1557 | data1_writes[1] = *write_failure; |
| 1558 | } else { |
| 1559 | ASSERT_TRUE(read_failure); |
| 1560 | data1_reads[2] = *read_failure; |
| 1561 | } |
| 1562 | |
| 1563 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1564 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1565 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1566 | |
| 1567 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1568 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1569 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1570 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1571 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1572 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1573 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1574 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1575 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1576 | "hello", "world" |
| 1577 | }; |
| 1578 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1579 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1580 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1581 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1585 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1587 | |
| 1588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1589 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1590 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1591 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1592 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1593 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1594 | if (i == 0) { |
| 1595 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1596 | } else { |
| 1597 | // The second request should be using a new socket. |
| 1598 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1599 | } |
| 1600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1601 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1602 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1603 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1604 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1605 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1606 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1607 | |
| 1608 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1609 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1610 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1611 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1612 | } |
| 1613 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1614 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1615 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1616 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1617 | const MockRead* read_failure, |
| 1618 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1619 | HttpRequestInfo request; |
| 1620 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1621 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1622 | request.traffic_annotation = |
| 1623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1624 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1625 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1626 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1628 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1629 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1630 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1631 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1632 | ssl1.next_proto = kProtoHTTP2; |
| 1633 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1634 | } |
| 1635 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1637 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1638 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1639 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1640 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1641 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1642 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1643 | SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 1644 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1645 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1646 | // HTTP/1.1 versions of the request and response. |
| 1647 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1648 | "Host: www.foo.com\r\n" |
| 1649 | "Connection: keep-alive\r\n\r\n"; |
| 1650 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1651 | const char kHttpData[] = "hello"; |
| 1652 | |
| 1653 | std::vector<MockRead> data1_reads; |
| 1654 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1655 | if (write_failure) { |
| 1656 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1657 | data1_writes.push_back(*write_failure); |
| 1658 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1659 | } else { |
| 1660 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1661 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1662 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1663 | } else { |
| 1664 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1665 | } |
| 1666 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1667 | } |
| 1668 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1669 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1670 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1671 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1672 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1673 | std::vector<MockRead> data2_reads; |
| 1674 | std::vector<MockWrite> data2_writes; |
| 1675 | |
| 1676 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1677 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1678 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1679 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1680 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1681 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1682 | } else { |
| 1683 | data2_writes.push_back( |
| 1684 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1685 | |
| 1686 | data2_reads.push_back( |
| 1687 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1688 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1689 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1690 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1691 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1692 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1693 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1694 | |
| 1695 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1696 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1697 | // Wait for the preconnect to complete. |
| 1698 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1699 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1700 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1701 | |
| 1702 | // Make the request. |
| 1703 | TestCompletionCallback callback; |
| 1704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1706 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1707 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1709 | |
| 1710 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1712 | |
| 1713 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1714 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1715 | TestLoadTimingNotReused( |
| 1716 | load_timing_info, |
| 1717 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1719 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1720 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1721 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1722 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1723 | if (response->was_fetched_via_spdy) { |
| 1724 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1725 | } else { |
| 1726 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1727 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1728 | |
| 1729 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1730 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1732 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1733 | } |
| 1734 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1735 | // Test that we do not retry indefinitely when a server sends an error like |
| 1736 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1737 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1738 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1739 | HttpRequestInfo request; |
| 1740 | request.method = "GET"; |
| 1741 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1742 | request.traffic_annotation = |
| 1743 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1744 | |
| 1745 | // Check whether we give up after the third try. |
| 1746 | |
| 1747 | // Construct an HTTP2 request and a "Go away" response. |
| 1748 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1749 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1750 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1751 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1752 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1753 | |
| 1754 | // Three go away responses. |
| 1755 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1756 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1757 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1758 | |
| 1759 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1760 | AddSSLSocketData(); |
| 1761 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1762 | AddSSLSocketData(); |
| 1763 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1764 | AddSSLSocketData(); |
| 1765 | |
| 1766 | TestCompletionCallback callback; |
| 1767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1769 | |
| 1770 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1772 | |
| 1773 | rv = callback.WaitForResult(); |
| 1774 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1775 | } |
| 1776 | |
| 1777 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1778 | HttpRequestInfo request; |
| 1779 | request.method = "GET"; |
| 1780 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1781 | request.traffic_annotation = |
| 1782 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1783 | |
| 1784 | // Check whether we try atleast thrice before giving up. |
| 1785 | |
| 1786 | // Construct an HTTP2 request and a "Go away" response. |
| 1787 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1788 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Bence Béky | dcb3009 | 2018-02-11 01:32:29 | [diff] [blame] | 1789 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway(0)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1790 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1791 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1792 | |
| 1793 | // Construct a non error HTTP2 response. |
| 1794 | SpdySerializedFrame spdy_response_no_error( |
| 1795 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1796 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1797 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1798 | CreateMockRead(spdy_data, 2)}; |
| 1799 | |
| 1800 | // Two error responses. |
| 1801 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1802 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1803 | // Followed by a success response. |
| 1804 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1805 | |
| 1806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1807 | AddSSLSocketData(); |
| 1808 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1809 | AddSSLSocketData(); |
| 1810 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1811 | AddSSLSocketData(); |
| 1812 | |
| 1813 | TestCompletionCallback callback; |
| 1814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1816 | |
| 1817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1819 | |
| 1820 | rv = callback.WaitForResult(); |
| 1821 | EXPECT_THAT(rv, IsOk()); |
| 1822 | } |
| 1823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1824 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1825 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1826 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1827 | } |
| 1828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1829 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1830 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1831 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1832 | } |
| 1833 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1834 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1835 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1836 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1837 | } |
| 1838 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1839 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1840 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1841 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1842 | MockRead read_failure(SYNCHRONOUS, |
| 1843 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1844 | "Connection: Keep-Alive\r\n" |
| 1845 | "Content-Length: 6\r\n\r\n" |
| 1846 | "Pickle"); |
| 1847 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1848 | } |
| 1849 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1850 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1851 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1852 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1853 | } |
| 1854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1855 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1856 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1857 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1858 | } |
| 1859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1860 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1861 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1862 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1863 | } |
| 1864 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1865 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1866 | MockRead read_failure(ASYNC, OK); // EOF |
| 1867 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1868 | } |
| 1869 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1870 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1871 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1872 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1873 | MockRead read_failure(SYNCHRONOUS, |
| 1874 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1875 | "Connection: Keep-Alive\r\n" |
| 1876 | "Content-Length: 6\r\n\r\n" |
| 1877 | "Pickle"); |
| 1878 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1879 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1880 | } |
| 1881 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1882 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1883 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1884 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1885 | } |
| 1886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1887 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1888 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1889 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1890 | } |
| 1891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1892 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1893 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1894 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1895 | } |
| 1896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1897 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1898 | MockRead read_failure(ASYNC, OK); // EOF |
| 1899 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1900 | } |
| 1901 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1902 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1903 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 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] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1910 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1911 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1912 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1913 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1914 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1915 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1917 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1918 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1919 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1921 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1923 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1925 | |
| 1926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1927 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1928 | |
| 1929 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1930 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1931 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | // What do various browsers do when the server closes a non-keepalive |
| 1935 | // connection without sending any response header or body? |
| 1936 | // |
| 1937 | // IE7: error page |
| 1938 | // Safari 3.1.2 (Windows): error page |
| 1939 | // Firefox 3.0.1: blank page |
| 1940 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1941 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1942 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1943 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1944 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1945 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1946 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1947 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1948 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1949 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1950 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1951 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1952 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1953 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1954 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1955 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1956 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1957 | // destructor in such situations. |
| 1958 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1959 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1960 | HttpRequestInfo request; |
| 1961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1962 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1963 | request.traffic_annotation = |
| 1964 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1965 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1967 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1968 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1969 | |
| 1970 | MockRead data_reads[] = { |
| 1971 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1972 | MockRead("Connection: keep-alive\r\n"), |
| 1973 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1974 | MockRead("hello"), |
| 1975 | MockRead(SYNCHRONOUS, 0), |
| 1976 | }; |
| 1977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1979 | |
| 1980 | TestCompletionCallback callback; |
| 1981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1982 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1984 | |
| 1985 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1987 | |
| 1988 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1989 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1990 | if (rv == ERR_IO_PENDING) |
| 1991 | rv = callback.WaitForResult(); |
| 1992 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1993 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1994 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1995 | |
| 1996 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1997 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1998 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1999 | } |
| 2000 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2001 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2002 | HttpRequestInfo request; |
| 2003 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2004 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2005 | request.traffic_annotation = |
| 2006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2007 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2009 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2010 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2011 | |
| 2012 | MockRead data_reads[] = { |
| 2013 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2014 | MockRead("Connection: keep-alive\r\n"), |
| 2015 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2016 | MockRead(SYNCHRONOUS, 0), |
| 2017 | }; |
| 2018 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2020 | |
| 2021 | TestCompletionCallback callback; |
| 2022 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2023 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2025 | |
| 2026 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2027 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2028 | |
| 2029 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2030 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2031 | if (rv == ERR_IO_PENDING) |
| 2032 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2033 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2034 | |
| 2035 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2036 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2037 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2038 | } |
| 2039 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2040 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2041 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2042 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2043 | HttpRequestInfo request; |
| 2044 | request.method = "GET"; |
| 2045 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2046 | request.traffic_annotation = |
| 2047 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2048 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2049 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2050 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2052 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2053 | const char* request_data = |
| 2054 | "GET / HTTP/1.1\r\n" |
| 2055 | "Host: www.foo.com\r\n" |
| 2056 | "Connection: keep-alive\r\n\r\n"; |
| 2057 | MockWrite data_writes[] = { |
| 2058 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2059 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2060 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2061 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2062 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2063 | }; |
| 2064 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2065 | // Note that because all these reads happen in the same |
| 2066 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2067 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2068 | MockRead data_reads[] = { |
| 2069 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2070 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2071 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2072 | MockRead(ASYNC, 7, |
| 2073 | "HTTP/1.1 302 Found\r\n" |
| 2074 | "Content-Length: 0\r\n\r\n"), |
| 2075 | MockRead(ASYNC, 9, |
| 2076 | "HTTP/1.1 302 Found\r\n" |
| 2077 | "Content-Length: 5\r\n\r\n" |
| 2078 | "hello"), |
| 2079 | MockRead(ASYNC, 11, |
| 2080 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2081 | "Content-Length: 0\r\n\r\n"), |
| 2082 | MockRead(ASYNC, 13, |
| 2083 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2084 | "Content-Length: 5\r\n\r\n" |
| 2085 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2086 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2087 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2088 | // the set_busy_before_sync_reads(true) call, while the |
| 2089 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2090 | // reuseable. See http://crbug.com/544255. |
| 2091 | MockRead(ASYNC, 15, |
| 2092 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2093 | "Content-Length: 5\r\n\r\n"), |
| 2094 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2095 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2096 | MockRead(ASYNC, 18, |
| 2097 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2098 | "Content-Length: 5\r\n\r\n" |
| 2099 | "he"), |
| 2100 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2101 | |
| 2102 | // The body of the final request is actually read. |
| 2103 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2104 | MockRead(ASYNC, 22, "hello"), |
| 2105 | }; |
| 2106 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2107 | arraysize(data_writes)); |
| 2108 | data.set_busy_before_sync_reads(true); |
| 2109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2110 | |
| 2111 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2112 | std::string response_lines[kNumUnreadBodies]; |
| 2113 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2114 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2115 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2116 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2117 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2118 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2119 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2120 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2121 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2122 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2123 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2124 | LoadTimingInfo load_timing_info; |
| 2125 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2126 | if (i == 0) { |
| 2127 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2128 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2129 | } else { |
| 2130 | TestLoadTimingReused(load_timing_info); |
| 2131 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2132 | } |
| 2133 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2134 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2135 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2136 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2137 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2138 | response_lines[i] = response->headers->GetStatusLine(); |
| 2139 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2140 | // Delete the transaction without reading the response bodies. Then spin |
| 2141 | // the message loop, so the response bodies are drained. |
| 2142 | trans.reset(); |
| 2143 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2144 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2145 | |
| 2146 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2147 | "HTTP/1.1 204 No Content", |
| 2148 | "HTTP/1.1 205 Reset Content", |
| 2149 | "HTTP/1.1 304 Not Modified", |
| 2150 | "HTTP/1.1 302 Found", |
| 2151 | "HTTP/1.1 302 Found", |
| 2152 | "HTTP/1.1 301 Moved Permanently", |
| 2153 | "HTTP/1.1 301 Moved Permanently", |
| 2154 | "HTTP/1.1 200 Hunky-Dory", |
| 2155 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2156 | }; |
| 2157 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2158 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2159 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2160 | |
| 2161 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2162 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2164 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2165 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2166 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2167 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2168 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2169 | ASSERT_TRUE(response); |
| 2170 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2171 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2172 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2173 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2174 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2175 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2176 | } |
| 2177 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2178 | // Sockets that receive extra data after a response is complete should not be |
| 2179 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2180 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2181 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2182 | MockWrite data_writes1[] = { |
| 2183 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2184 | "Host: www.borked.com\r\n" |
| 2185 | "Connection: keep-alive\r\n\r\n"), |
| 2186 | }; |
| 2187 | |
| 2188 | MockRead data_reads1[] = { |
| 2189 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2190 | "Connection: keep-alive\r\n" |
| 2191 | "Content-Length: 22\r\n\r\n" |
| 2192 | "This server is borked."), |
| 2193 | }; |
| 2194 | |
| 2195 | MockWrite data_writes2[] = { |
| 2196 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2197 | "Host: www.borked.com\r\n" |
| 2198 | "Connection: keep-alive\r\n\r\n"), |
| 2199 | }; |
| 2200 | |
| 2201 | MockRead data_reads2[] = { |
| 2202 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2203 | "Content-Length: 3\r\n\r\n" |
| 2204 | "foo"), |
| 2205 | }; |
| 2206 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2207 | data_writes1, arraysize(data_writes1)); |
| 2208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2209 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2210 | data_writes2, arraysize(data_writes2)); |
| 2211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2212 | |
| 2213 | TestCompletionCallback callback; |
| 2214 | HttpRequestInfo request1; |
| 2215 | request1.method = "HEAD"; |
| 2216 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2217 | request1.traffic_annotation = |
| 2218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2219 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2220 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2221 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2222 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2224 | |
| 2225 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2226 | ASSERT_TRUE(response1); |
| 2227 | ASSERT_TRUE(response1->headers); |
| 2228 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2229 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2230 | |
| 2231 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2232 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2233 | EXPECT_EQ("", response_data1); |
| 2234 | // Deleting the transaction attempts to release the socket back into the |
| 2235 | // socket pool. |
| 2236 | trans1.reset(); |
| 2237 | |
| 2238 | HttpRequestInfo request2; |
| 2239 | request2.method = "GET"; |
| 2240 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2241 | request2.traffic_annotation = |
| 2242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2243 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2244 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2245 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2246 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2247 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2248 | |
| 2249 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2250 | ASSERT_TRUE(response2); |
| 2251 | ASSERT_TRUE(response2->headers); |
| 2252 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2253 | |
| 2254 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2255 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2256 | EXPECT_EQ("foo", response_data2); |
| 2257 | } |
| 2258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2259 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2261 | MockWrite data_writes1[] = { |
| 2262 | MockWrite("GET / HTTP/1.1\r\n" |
| 2263 | "Host: www.borked.com\r\n" |
| 2264 | "Connection: keep-alive\r\n\r\n"), |
| 2265 | }; |
| 2266 | |
| 2267 | MockRead data_reads1[] = { |
| 2268 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2269 | "Connection: keep-alive\r\n" |
| 2270 | "Content-Length: 22\r\n\r\n" |
| 2271 | "This server is borked." |
| 2272 | "Bonus data!"), |
| 2273 | }; |
| 2274 | |
| 2275 | MockWrite data_writes2[] = { |
| 2276 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2277 | "Host: www.borked.com\r\n" |
| 2278 | "Connection: keep-alive\r\n\r\n"), |
| 2279 | }; |
| 2280 | |
| 2281 | MockRead data_reads2[] = { |
| 2282 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2283 | "Content-Length: 3\r\n\r\n" |
| 2284 | "foo"), |
| 2285 | }; |
| 2286 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2287 | data_writes1, arraysize(data_writes1)); |
| 2288 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2289 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2290 | data_writes2, arraysize(data_writes2)); |
| 2291 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2292 | |
| 2293 | TestCompletionCallback callback; |
| 2294 | HttpRequestInfo request1; |
| 2295 | request1.method = "GET"; |
| 2296 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2297 | request1.traffic_annotation = |
| 2298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2299 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2300 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2301 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2302 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2303 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2304 | |
| 2305 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2306 | ASSERT_TRUE(response1); |
| 2307 | ASSERT_TRUE(response1->headers); |
| 2308 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2309 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2310 | |
| 2311 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2312 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2313 | EXPECT_EQ("This server is borked.", response_data1); |
| 2314 | // Deleting the transaction attempts to release the socket back into the |
| 2315 | // socket pool. |
| 2316 | trans1.reset(); |
| 2317 | |
| 2318 | HttpRequestInfo request2; |
| 2319 | request2.method = "GET"; |
| 2320 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2321 | request2.traffic_annotation = |
| 2322 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2323 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2324 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2325 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2326 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2327 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2328 | |
| 2329 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2330 | ASSERT_TRUE(response2); |
| 2331 | ASSERT_TRUE(response2->headers); |
| 2332 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2333 | |
| 2334 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2335 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2336 | EXPECT_EQ("foo", response_data2); |
| 2337 | } |
| 2338 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2339 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2341 | MockWrite data_writes1[] = { |
| 2342 | MockWrite("GET / HTTP/1.1\r\n" |
| 2343 | "Host: www.borked.com\r\n" |
| 2344 | "Connection: keep-alive\r\n\r\n"), |
| 2345 | }; |
| 2346 | |
| 2347 | MockRead data_reads1[] = { |
| 2348 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2349 | "Connection: keep-alive\r\n" |
| 2350 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2351 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2352 | MockRead("0\r\n\r\nBonus data!"), |
| 2353 | }; |
| 2354 | |
| 2355 | MockWrite data_writes2[] = { |
| 2356 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2357 | "Host: www.borked.com\r\n" |
| 2358 | "Connection: keep-alive\r\n\r\n"), |
| 2359 | }; |
| 2360 | |
| 2361 | MockRead data_reads2[] = { |
| 2362 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2363 | "Content-Length: 3\r\n\r\n" |
| 2364 | "foo"), |
| 2365 | }; |
| 2366 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2367 | data_writes1, arraysize(data_writes1)); |
| 2368 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2369 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2370 | data_writes2, arraysize(data_writes2)); |
| 2371 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2372 | |
| 2373 | TestCompletionCallback callback; |
| 2374 | HttpRequestInfo request1; |
| 2375 | request1.method = "GET"; |
| 2376 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2377 | request1.traffic_annotation = |
| 2378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2379 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2380 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2381 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2382 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2383 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2384 | |
| 2385 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2386 | ASSERT_TRUE(response1); |
| 2387 | ASSERT_TRUE(response1->headers); |
| 2388 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2389 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2390 | |
| 2391 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2392 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2393 | EXPECT_EQ("This server is borked.", response_data1); |
| 2394 | // Deleting the transaction attempts to release the socket back into the |
| 2395 | // socket pool. |
| 2396 | trans1.reset(); |
| 2397 | |
| 2398 | HttpRequestInfo request2; |
| 2399 | request2.method = "GET"; |
| 2400 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2401 | request2.traffic_annotation = |
| 2402 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2403 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2404 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2405 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2406 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2407 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2408 | |
| 2409 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2410 | ASSERT_TRUE(response2); |
| 2411 | ASSERT_TRUE(response2->headers); |
| 2412 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2413 | |
| 2414 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2415 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2416 | EXPECT_EQ("foo", response_data2); |
| 2417 | } |
| 2418 | |
| 2419 | // This is a little different from the others - it tests the case that the |
| 2420 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2421 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2422 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2423 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2425 | MockWrite data_writes1[] = { |
| 2426 | MockWrite("GET / HTTP/1.1\r\n" |
| 2427 | "Host: www.borked.com\r\n" |
| 2428 | "Connection: keep-alive\r\n\r\n"), |
| 2429 | }; |
| 2430 | |
| 2431 | MockRead data_reads1[] = { |
| 2432 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2433 | "Connection: keep-alive\r\n" |
| 2434 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2435 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2436 | MockRead("0\r\n\r\nBonus data!"), |
| 2437 | }; |
| 2438 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2439 | data_writes1, arraysize(data_writes1)); |
| 2440 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2441 | |
| 2442 | TestCompletionCallback callback; |
| 2443 | HttpRequestInfo request1; |
| 2444 | request1.method = "GET"; |
| 2445 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2446 | request1.traffic_annotation = |
| 2447 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2448 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2449 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2450 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2451 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2452 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2453 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2454 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2455 | ASSERT_TRUE(response1); |
| 2456 | ASSERT_TRUE(response1->headers); |
| 2457 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2458 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2459 | |
| 2460 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2461 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2462 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2463 | |
| 2464 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2465 | // socket can't be reused, rather than returning it to the socket pool. |
| 2466 | base::RunLoop().RunUntilIdle(); |
| 2467 | |
| 2468 | // There should be no idle sockets in the pool. |
| 2469 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2470 | } |
| 2471 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2472 | // Test the request-challenge-retry sequence for basic auth. |
| 2473 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2474 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2475 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2476 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2477 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2478 | request.traffic_annotation = |
| 2479 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2480 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2481 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2482 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2484 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2485 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2486 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2487 | MockWrite( |
| 2488 | "GET / HTTP/1.1\r\n" |
| 2489 | "Host: www.example.org\r\n" |
| 2490 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2491 | }; |
| 2492 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2493 | MockRead data_reads1[] = { |
| 2494 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2495 | // Give a couple authenticate options (only the middle one is actually |
| 2496 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2497 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2498 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2499 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2500 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2501 | // Large content-length -- won't matter, as connection will be reset. |
| 2502 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2503 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2504 | }; |
| 2505 | |
| 2506 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2507 | // be issuing -- the final header line contains the credentials. |
| 2508 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2509 | MockWrite( |
| 2510 | "GET / HTTP/1.1\r\n" |
| 2511 | "Host: www.example.org\r\n" |
| 2512 | "Connection: keep-alive\r\n" |
| 2513 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2514 | }; |
| 2515 | |
| 2516 | // Lastly, the server responds with the actual content. |
| 2517 | MockRead data_reads2[] = { |
| 2518 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2519 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2520 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2521 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2522 | }; |
| 2523 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2524 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2525 | data_writes1, arraysize(data_writes1)); |
| 2526 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2527 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2528 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2529 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2530 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2531 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2532 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2533 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2535 | |
| 2536 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2537 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2538 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2539 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2540 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2541 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2542 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2543 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2544 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2545 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2546 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2548 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2549 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2550 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2552 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2554 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2556 | |
| 2557 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2558 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2559 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2560 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2561 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2562 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2563 | // The load timing after restart should have a new socket ID, and times after |
| 2564 | // those of the first load timing. |
| 2565 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2566 | load_timing_info2.connect_timing.connect_start); |
| 2567 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2568 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2569 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2570 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2571 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2572 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2573 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2574 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2575 | ASSERT_TRUE(response); |
| 2576 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2577 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2578 | } |
| 2579 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2580 | // Test the request-challenge-retry sequence for basic auth. |
| 2581 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2582 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2583 | HttpRequestInfo request; |
| 2584 | request.method = "GET"; |
| 2585 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2586 | request.traffic_annotation = |
| 2587 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2588 | |
| 2589 | TestNetLog log; |
| 2590 | MockHostResolver* resolver = new MockHostResolver(); |
| 2591 | session_deps_.net_log = &log; |
| 2592 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2593 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2595 | |
| 2596 | resolver->rules()->ClearRules(); |
| 2597 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2598 | |
| 2599 | MockWrite data_writes1[] = { |
| 2600 | MockWrite("GET / HTTP/1.1\r\n" |
| 2601 | "Host: www.example.org\r\n" |
| 2602 | "Connection: keep-alive\r\n\r\n"), |
| 2603 | }; |
| 2604 | |
| 2605 | MockRead data_reads1[] = { |
| 2606 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2607 | // Give a couple authenticate options (only the middle one is actually |
| 2608 | // supported). |
| 2609 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2610 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2611 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2612 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2613 | // Large content-length -- won't matter, as connection will be reset. |
| 2614 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2615 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2616 | }; |
| 2617 | |
| 2618 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2619 | // be issuing -- the final header line contains the credentials. |
| 2620 | MockWrite data_writes2[] = { |
| 2621 | MockWrite("GET / HTTP/1.1\r\n" |
| 2622 | "Host: www.example.org\r\n" |
| 2623 | "Connection: keep-alive\r\n" |
| 2624 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2625 | }; |
| 2626 | |
| 2627 | // Lastly, the server responds with the actual content. |
| 2628 | MockRead data_reads2[] = { |
| 2629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2630 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2631 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2632 | }; |
| 2633 | |
| 2634 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2635 | data_writes1, arraysize(data_writes1)); |
| 2636 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2637 | data_writes2, arraysize(data_writes2)); |
| 2638 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2639 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2640 | |
| 2641 | TestCompletionCallback callback1; |
| 2642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2643 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2644 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2645 | |
| 2646 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2647 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2648 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2649 | |
| 2650 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2651 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2652 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2655 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2656 | ASSERT_TRUE(response); |
| 2657 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2658 | |
| 2659 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2660 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2661 | ASSERT_FALSE(endpoint.address().empty()); |
| 2662 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2663 | |
| 2664 | resolver->rules()->ClearRules(); |
| 2665 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2666 | |
| 2667 | TestCompletionCallback callback2; |
| 2668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2669 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2670 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2671 | |
| 2672 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2673 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2674 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2675 | // The load timing after restart should have a new socket ID, and times after |
| 2676 | // those of the first load timing. |
| 2677 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2678 | load_timing_info2.connect_timing.connect_start); |
| 2679 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2680 | |
| 2681 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2682 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2683 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2684 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2685 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2686 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2687 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2688 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2689 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2691 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2692 | ASSERT_FALSE(endpoint.address().empty()); |
| 2693 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2694 | } |
| 2695 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2696 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2697 | HttpRequestInfo request; |
| 2698 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2699 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2700 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2701 | request.traffic_annotation = |
| 2702 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2703 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2706 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2707 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2708 | MockWrite( |
| 2709 | "GET / HTTP/1.1\r\n" |
| 2710 | "Host: www.example.org\r\n" |
| 2711 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2712 | }; |
| 2713 | |
| 2714 | MockRead data_reads[] = { |
| 2715 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2716 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2717 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2718 | // Large content-length -- won't matter, as connection will be reset. |
| 2719 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2720 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2721 | }; |
| 2722 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2723 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2724 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2725 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2726 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2727 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2728 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2730 | |
| 2731 | rv = callback.WaitForResult(); |
| 2732 | EXPECT_EQ(0, rv); |
| 2733 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2734 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2735 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2736 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2739 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2740 | ASSERT_TRUE(response); |
| 2741 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2742 | } |
| 2743 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2744 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2745 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2746 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2747 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2748 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2749 | // reused. See http://crbug.com/544255. |
| 2750 | for (int i = 0; i < 2; ++i) { |
| 2751 | HttpRequestInfo request; |
| 2752 | request.method = "GET"; |
| 2753 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2754 | request.traffic_annotation = |
| 2755 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2756 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2757 | TestNetLog log; |
| 2758 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2760 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2761 | MockWrite data_writes[] = { |
| 2762 | MockWrite(ASYNC, 0, |
| 2763 | "GET / HTTP/1.1\r\n" |
| 2764 | "Host: www.example.org\r\n" |
| 2765 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2768 | // be issuing -- the final header line contains the credentials. |
| 2769 | MockWrite(ASYNC, 6, |
| 2770 | "GET / HTTP/1.1\r\n" |
| 2771 | "Host: www.example.org\r\n" |
| 2772 | "Connection: keep-alive\r\n" |
| 2773 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2774 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2775 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2776 | MockRead data_reads[] = { |
| 2777 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2778 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2779 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2780 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2781 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2783 | // Lastly, the server responds with the actual content. |
| 2784 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2785 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2786 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2787 | MockRead(ASYNC, 10, "Hello"), |
| 2788 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2789 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2790 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2791 | arraysize(data_writes)); |
| 2792 | data.set_busy_before_sync_reads(true); |
| 2793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2794 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2795 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2798 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2799 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2801 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2803 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2805 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2806 | ASSERT_TRUE(response); |
| 2807 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2808 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2809 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2811 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2812 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2813 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2814 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2815 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2816 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2817 | TestLoadTimingReused(load_timing_info2); |
| 2818 | // The load timing after restart should have the same socket ID, and times |
| 2819 | // those of the first load timing. |
| 2820 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2821 | load_timing_info2.send_start); |
| 2822 | 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] | 2823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2824 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2825 | ASSERT_TRUE(response); |
| 2826 | EXPECT_FALSE(response->auth_challenge); |
| 2827 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2828 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2829 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2830 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2831 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2832 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2833 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2834 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2835 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2836 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2840 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2841 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2842 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2844 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2845 | request.traffic_annotation = |
| 2846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2847 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2849 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2850 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2851 | MockWrite("GET / HTTP/1.1\r\n" |
| 2852 | "Host: www.example.org\r\n" |
| 2853 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2854 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2855 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2856 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2857 | MockWrite("GET / HTTP/1.1\r\n" |
| 2858 | "Host: www.example.org\r\n" |
| 2859 | "Connection: keep-alive\r\n" |
| 2860 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2861 | }; |
| 2862 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2863 | MockRead data_reads1[] = { |
| 2864 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2865 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2866 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2867 | |
| 2868 | // Lastly, the server responds with the actual content. |
| 2869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2870 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2871 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2872 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2873 | }; |
| 2874 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2875 | // An incorrect reconnect would cause this to be read. |
| 2876 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2877 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2878 | }; |
| 2879 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2880 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2881 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2882 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2883 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2885 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2887 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2890 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2892 | |
| 2893 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2897 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2898 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2900 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2902 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | |
| 2905 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2908 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2909 | ASSERT_TRUE(response); |
| 2910 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2911 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2912 | } |
| 2913 | |
| 2914 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2915 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2916 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2917 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2919 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2920 | request.traffic_annotation = |
| 2921 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2924 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2925 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | MockWrite("GET / HTTP/1.1\r\n" |
| 2927 | "Host: www.example.org\r\n" |
| 2928 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2930 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2931 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2932 | MockWrite("GET / HTTP/1.1\r\n" |
| 2933 | "Host: www.example.org\r\n" |
| 2934 | "Connection: keep-alive\r\n" |
| 2935 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | }; |
| 2937 | |
| 2938 | // Respond with 5 kb of response body. |
| 2939 | std::string large_body_string("Unauthorized"); |
| 2940 | large_body_string.append(5 * 1024, ' '); |
| 2941 | large_body_string.append("\r\n"); |
| 2942 | |
| 2943 | MockRead data_reads1[] = { |
| 2944 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2945 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2946 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2947 | // 5134 = 12 + 5 * 1024 + 2 |
| 2948 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2949 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
| 2951 | // Lastly, the server responds with the actual content. |
| 2952 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2953 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2954 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2955 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2956 | }; |
| 2957 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2958 | // An incorrect reconnect would cause this to be read. |
| 2959 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2960 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2961 | }; |
| 2962 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2963 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2964 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2965 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2966 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2967 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2968 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2969 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2970 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2973 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2974 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2975 | |
| 2976 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2977 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2979 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2980 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2981 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2983 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2985 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2987 | |
| 2988 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2991 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2992 | ASSERT_TRUE(response); |
| 2993 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2994 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2995 | } |
| 2996 | |
| 2997 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2998 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2999 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3000 | HttpRequestInfo request; |
| 3001 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3002 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3003 | request.traffic_annotation = |
| 3004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3005 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3007 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3008 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3009 | MockWrite( |
| 3010 | "GET / HTTP/1.1\r\n" |
| 3011 | "Host: www.example.org\r\n" |
| 3012 | "Connection: keep-alive\r\n\r\n"), |
| 3013 | // This simulates the seemingly successful write to a closed connection |
| 3014 | // if the bug is not fixed. |
| 3015 | MockWrite( |
| 3016 | "GET / HTTP/1.1\r\n" |
| 3017 | "Host: www.example.org\r\n" |
| 3018 | "Connection: keep-alive\r\n" |
| 3019 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3020 | }; |
| 3021 | |
| 3022 | MockRead data_reads1[] = { |
| 3023 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3024 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3025 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3026 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3027 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3028 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3029 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3030 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3031 | }; |
| 3032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3033 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3034 | // be issuing -- the final header line contains the credentials. |
| 3035 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3036 | MockWrite( |
| 3037 | "GET / HTTP/1.1\r\n" |
| 3038 | "Host: www.example.org\r\n" |
| 3039 | "Connection: keep-alive\r\n" |
| 3040 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3041 | }; |
| 3042 | |
| 3043 | // Lastly, the server responds with the actual content. |
| 3044 | MockRead data_reads2[] = { |
| 3045 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3046 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3047 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3048 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3049 | }; |
| 3050 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3051 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3052 | data_writes1, arraysize(data_writes1)); |
| 3053 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3054 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3055 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3056 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3057 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3058 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3060 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3061 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3063 | |
| 3064 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3068 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3069 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3071 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3073 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3075 | |
| 3076 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3077 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3079 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3080 | ASSERT_TRUE(response); |
| 3081 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3082 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3083 | } |
| 3084 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3085 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3086 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3087 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3088 | HttpRequestInfo request; |
| 3089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3090 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3091 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3092 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3093 | request.traffic_annotation = |
| 3094 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3095 | |
| 3096 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3097 | session_deps_.proxy_resolution_service = |
| 3098 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3099 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3100 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3102 | |
| 3103 | // Since we have proxy, should try to establish tunnel. |
| 3104 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3105 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3106 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3107 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3108 | }; |
| 3109 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3110 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3111 | // connection. |
| 3112 | MockRead data_reads1[] = { |
| 3113 | // No credentials. |
| 3114 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3115 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3116 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3117 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3118 | // Since the first connection couldn't be reused, need to establish another |
| 3119 | // once given credentials. |
| 3120 | MockWrite data_writes2[] = { |
| 3121 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3122 | // be issuing -- the final header line contains the credentials. |
| 3123 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3124 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3125 | "Proxy-Connection: keep-alive\r\n" |
| 3126 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3127 | |
| 3128 | MockWrite("GET / HTTP/1.1\r\n" |
| 3129 | "Host: www.example.org\r\n" |
| 3130 | "Connection: keep-alive\r\n\r\n"), |
| 3131 | }; |
| 3132 | |
| 3133 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3134 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3135 | |
| 3136 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3137 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3138 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3139 | MockRead(SYNCHRONOUS, "hello"), |
| 3140 | }; |
| 3141 | |
| 3142 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3143 | data_writes1, arraysize(data_writes1)); |
| 3144 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3145 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3146 | data_writes2, arraysize(data_writes2)); |
| 3147 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3148 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3149 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3150 | |
| 3151 | TestCompletionCallback callback1; |
| 3152 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3153 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3154 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3155 | |
| 3156 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3158 | |
| 3159 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3160 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3161 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3162 | log.GetEntries(&entries); |
| 3163 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3164 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3165 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3166 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3167 | entries, pos, |
| 3168 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3169 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3170 | |
| 3171 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3172 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3173 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3174 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3175 | EXPECT_EQ(407, response->headers->response_code()); |
| 3176 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3177 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3178 | |
| 3179 | LoadTimingInfo load_timing_info; |
| 3180 | // CONNECT requests and responses are handled at the connect job level, so |
| 3181 | // the transaction does not yet have a connection. |
| 3182 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3183 | |
| 3184 | TestCompletionCallback callback2; |
| 3185 | |
| 3186 | rv = |
| 3187 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3188 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3189 | |
| 3190 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3191 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3192 | |
| 3193 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3194 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3195 | |
| 3196 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3197 | EXPECT_EQ(200, response->headers->response_code()); |
| 3198 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3199 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3200 | |
| 3201 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3202 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3203 | |
| 3204 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3205 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3206 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3207 | |
| 3208 | trans.reset(); |
| 3209 | session->CloseAllConnections(); |
| 3210 | } |
| 3211 | |
| 3212 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3213 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3214 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3215 | HttpRequestInfo request; |
| 3216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3217 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3218 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3219 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3220 | request.traffic_annotation = |
| 3221 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3222 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3223 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3224 | session_deps_.proxy_resolution_service = |
| 3225 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3226 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3227 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3229 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3230 | // Since we have proxy, should try to establish tunnel. |
| 3231 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3232 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3233 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3234 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3235 | }; |
| 3236 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3237 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3238 | // connection. |
| 3239 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3240 | // No credentials. |
| 3241 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3242 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3243 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3244 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3245 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3246 | MockWrite data_writes2[] = { |
| 3247 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3248 | // be issuing -- the final header line contains the credentials. |
| 3249 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3250 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3251 | "Proxy-Connection: keep-alive\r\n" |
| 3252 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3253 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3254 | MockWrite("GET / HTTP/1.1\r\n" |
| 3255 | "Host: www.example.org\r\n" |
| 3256 | "Connection: keep-alive\r\n\r\n"), |
| 3257 | }; |
| 3258 | |
| 3259 | MockRead data_reads2[] = { |
| 3260 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3261 | |
| 3262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3263 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3264 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3265 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3266 | }; |
| 3267 | |
| 3268 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3269 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3270 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3271 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3272 | data_writes2, arraysize(data_writes2)); |
| 3273 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3274 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3277 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3278 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3279 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3280 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3282 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3284 | |
| 3285 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3286 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3287 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3288 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3289 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3290 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3291 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3292 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3293 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3294 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3295 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3296 | |
| 3297 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3298 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3299 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3300 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3301 | EXPECT_EQ(407, response->headers->response_code()); |
| 3302 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3303 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3304 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3305 | LoadTimingInfo load_timing_info; |
| 3306 | // CONNECT requests and responses are handled at the connect job level, so |
| 3307 | // the transaction does not yet have a connection. |
| 3308 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3310 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3311 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3312 | rv = trans->RestartWithAuth( |
| 3313 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3314 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3315 | |
| 3316 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3318 | |
| 3319 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3320 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3321 | |
| 3322 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3323 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3324 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3325 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3326 | |
| 3327 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3328 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3329 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3330 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3331 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3332 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3333 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3334 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3335 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3336 | } |
| 3337 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3338 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3340 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3341 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3342 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3343 | // reused. See http://crbug.com/544255. |
| 3344 | for (int i = 0; i < 2; ++i) { |
| 3345 | HttpRequestInfo request; |
| 3346 | request.method = "GET"; |
| 3347 | request.url = GURL("https://www.example.org/"); |
| 3348 | // Ensure that proxy authentication is attempted even |
| 3349 | // when the no authentication data flag is set. |
| 3350 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3351 | request.traffic_annotation = |
| 3352 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3353 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3354 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3355 | session_deps_.proxy_resolution_service = |
| 3356 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3357 | BoundTestNetLog log; |
| 3358 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3363 | // Since we have proxy, should try to establish tunnel. |
| 3364 | MockWrite data_writes1[] = { |
| 3365 | MockWrite(ASYNC, 0, |
| 3366 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3367 | "Host: www.example.org:443\r\n" |
| 3368 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3370 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | // be issuing -- the final header line contains the credentials. |
| 3372 | MockWrite(ASYNC, 3, |
| 3373 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3374 | "Host: www.example.org:443\r\n" |
| 3375 | "Proxy-Connection: keep-alive\r\n" |
| 3376 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3377 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3379 | // The proxy responds to the connect with a 407, using a persistent |
| 3380 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3381 | MockRead data_reads1[] = { |
| 3382 | // No credentials. |
| 3383 | MockRead(ASYNC, 1, |
| 3384 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3385 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3386 | "Proxy-Connection: keep-alive\r\n" |
| 3387 | "Content-Length: 10\r\n\r\n"), |
| 3388 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3389 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3390 | // Wrong credentials (wrong password). |
| 3391 | MockRead(ASYNC, 4, |
| 3392 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3393 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3394 | "Proxy-Connection: keep-alive\r\n" |
| 3395 | "Content-Length: 10\r\n\r\n"), |
| 3396 | // No response body because the test stops reading here. |
| 3397 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3398 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3399 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3401 | arraysize(data_writes1)); |
| 3402 | data1.set_busy_before_sync_reads(true); |
| 3403 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3404 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3405 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3407 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3408 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3409 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3410 | TestNetLogEntry::List entries; |
| 3411 | log.GetEntries(&entries); |
| 3412 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3413 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3414 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | ExpectLogContainsSomewhere( |
| 3416 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3417 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3418 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3420 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3421 | ASSERT_TRUE(response); |
| 3422 | ASSERT_TRUE(response->headers); |
| 3423 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3424 | EXPECT_EQ(407, response->headers->response_code()); |
| 3425 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3426 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3427 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3428 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3429 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3430 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3431 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3432 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3433 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3434 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3436 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3437 | ASSERT_TRUE(response); |
| 3438 | ASSERT_TRUE(response->headers); |
| 3439 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3440 | EXPECT_EQ(407, response->headers->response_code()); |
| 3441 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3442 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3443 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3444 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3445 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3446 | // out of scope. |
| 3447 | session->CloseAllConnections(); |
| 3448 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3449 | } |
| 3450 | |
| 3451 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3452 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3453 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3455 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3456 | // reused. See http://crbug.com/544255. |
| 3457 | for (int i = 0; i < 2; ++i) { |
| 3458 | HttpRequestInfo request; |
| 3459 | request.method = "GET"; |
| 3460 | request.url = GURL("https://www.example.org/"); |
| 3461 | // Ensure that proxy authentication is attempted even |
| 3462 | // when the no authentication data flag is set. |
| 3463 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3464 | request.traffic_annotation = |
| 3465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3466 | |
| 3467 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3468 | session_deps_.proxy_resolution_service = |
| 3469 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3470 | BoundTestNetLog log; |
| 3471 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3475 | |
| 3476 | // Since we have proxy, should try to establish tunnel. |
| 3477 | MockWrite data_writes1[] = { |
| 3478 | MockWrite(ASYNC, 0, |
| 3479 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3480 | "Host: www.example.org:443\r\n" |
| 3481 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3483 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3484 | // be issuing -- the final header line contains the credentials. |
| 3485 | MockWrite(ASYNC, 3, |
| 3486 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3487 | "Host: www.example.org:443\r\n" |
| 3488 | "Proxy-Connection: keep-alive\r\n" |
| 3489 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3490 | }; |
| 3491 | |
| 3492 | // The proxy responds to the connect with a 407, using a persistent |
| 3493 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3494 | MockRead data_reads1[] = { |
| 3495 | // No credentials. |
| 3496 | MockRead(ASYNC, 1, |
| 3497 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3498 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3499 | "Content-Length: 10\r\n\r\n"), |
| 3500 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3501 | |
| 3502 | // Wrong credentials (wrong password). |
| 3503 | MockRead(ASYNC, 4, |
| 3504 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3505 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3506 | "Content-Length: 10\r\n\r\n"), |
| 3507 | // No response body because the test stops reading here. |
| 3508 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3509 | }; |
| 3510 | |
| 3511 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3512 | arraysize(data_writes1)); |
| 3513 | data1.set_busy_before_sync_reads(true); |
| 3514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3515 | |
| 3516 | TestCompletionCallback callback1; |
| 3517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3518 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3519 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3520 | |
| 3521 | TestNetLogEntry::List entries; |
| 3522 | log.GetEntries(&entries); |
| 3523 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3524 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3525 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3526 | ExpectLogContainsSomewhere( |
| 3527 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3528 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3529 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3531 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3532 | ASSERT_TRUE(response); |
| 3533 | ASSERT_TRUE(response->headers); |
| 3534 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3535 | EXPECT_EQ(407, response->headers->response_code()); |
| 3536 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3537 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3538 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3539 | |
| 3540 | TestCompletionCallback callback2; |
| 3541 | |
| 3542 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3543 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3544 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3545 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3546 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3547 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3548 | ASSERT_TRUE(response); |
| 3549 | ASSERT_TRUE(response->headers); |
| 3550 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3551 | EXPECT_EQ(407, response->headers->response_code()); |
| 3552 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3553 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3554 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3555 | |
| 3556 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3557 | // out of scope. |
| 3558 | session->CloseAllConnections(); |
| 3559 | } |
| 3560 | } |
| 3561 | |
| 3562 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3563 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3564 | // the case the server sends extra data on the original socket, so it can't be |
| 3565 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3566 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3567 | HttpRequestInfo request; |
| 3568 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3569 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3570 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3571 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3572 | request.traffic_annotation = |
| 3573 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3574 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3575 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3576 | session_deps_.proxy_resolution_service = |
| 3577 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3578 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3579 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3581 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3582 | // Since we have proxy, should try to establish tunnel. |
| 3583 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3584 | MockWrite(ASYNC, 0, |
| 3585 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3586 | "Host: www.example.org:443\r\n" |
| 3587 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3588 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3591 | // extra data, so the socket cannot be reused. |
| 3592 | MockRead data_reads1[] = { |
| 3593 | // No credentials. |
| 3594 | MockRead(ASYNC, 1, |
| 3595 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3596 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3597 | "Content-Length: 10\r\n\r\n"), |
| 3598 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3599 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3600 | }; |
| 3601 | |
| 3602 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3603 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3604 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3605 | MockWrite(ASYNC, 0, |
| 3606 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3607 | "Host: www.example.org:443\r\n" |
| 3608 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3609 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3610 | |
| 3611 | MockWrite(ASYNC, 2, |
| 3612 | "GET / HTTP/1.1\r\n" |
| 3613 | "Host: www.example.org\r\n" |
| 3614 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3615 | }; |
| 3616 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3617 | MockRead data_reads2[] = { |
| 3618 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3619 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | MockRead(ASYNC, 3, |
| 3621 | "HTTP/1.1 200 OK\r\n" |
| 3622 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3623 | "Content-Length: 5\r\n\r\n"), |
| 3624 | // No response body because the test stops reading here. |
| 3625 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3626 | }; |
| 3627 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3629 | arraysize(data_writes1)); |
| 3630 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3631 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3632 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3633 | arraysize(data_writes2)); |
| 3634 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3635 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3637 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3638 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3639 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3640 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3641 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3642 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3643 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3644 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3645 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3646 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3647 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3648 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3649 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3650 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3651 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3652 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3653 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3654 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3655 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3656 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3657 | ASSERT_TRUE(response); |
| 3658 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3659 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3660 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3661 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3662 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3663 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3664 | LoadTimingInfo load_timing_info; |
| 3665 | // CONNECT requests and responses are handled at the connect job level, so |
| 3666 | // the transaction does not yet have a connection. |
| 3667 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3669 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3670 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3671 | rv = |
| 3672 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3673 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3674 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3675 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | EXPECT_EQ(200, response->headers->response_code()); |
| 3677 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3678 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3679 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3680 | // The password prompt info should not be set. |
| 3681 | EXPECT_FALSE(response->auth_challenge); |
| 3682 | |
| 3683 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3684 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3685 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3686 | |
| 3687 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3688 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3689 | } |
| 3690 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3691 | // Test the case a proxy closes a socket while the challenge body is being |
| 3692 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3693 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3694 | HttpRequestInfo request; |
| 3695 | request.method = "GET"; |
| 3696 | request.url = GURL("https://www.example.org/"); |
| 3697 | // Ensure that proxy authentication is attempted even |
| 3698 | // when the no authentication data flag is set. |
| 3699 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3700 | request.traffic_annotation = |
| 3701 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3702 | |
| 3703 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3704 | session_deps_.proxy_resolution_service = |
| 3705 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3706 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3709 | |
| 3710 | // Since we have proxy, should try to establish tunnel. |
| 3711 | MockWrite data_writes1[] = { |
| 3712 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3713 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3714 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3715 | }; |
| 3716 | |
| 3717 | // The proxy responds to the connect with a 407, using a persistent |
| 3718 | // connection. |
| 3719 | MockRead data_reads1[] = { |
| 3720 | // No credentials. |
| 3721 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3722 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3723 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3724 | // Server hands up in the middle of the body. |
| 3725 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3726 | }; |
| 3727 | |
| 3728 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3729 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3730 | // be issuing -- the final header line contains the credentials. |
| 3731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3732 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3733 | "Proxy-Connection: keep-alive\r\n" |
| 3734 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3735 | |
| 3736 | MockWrite("GET / HTTP/1.1\r\n" |
| 3737 | "Host: www.example.org\r\n" |
| 3738 | "Connection: keep-alive\r\n\r\n"), |
| 3739 | }; |
| 3740 | |
| 3741 | MockRead data_reads2[] = { |
| 3742 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3743 | |
| 3744 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3745 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3746 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3747 | MockRead(SYNCHRONOUS, "hello"), |
| 3748 | }; |
| 3749 | |
| 3750 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3751 | data_writes1, arraysize(data_writes1)); |
| 3752 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3753 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3754 | data_writes2, arraysize(data_writes2)); |
| 3755 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3756 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3758 | |
| 3759 | TestCompletionCallback callback; |
| 3760 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3761 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3762 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3763 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3764 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3765 | ASSERT_TRUE(response); |
| 3766 | ASSERT_TRUE(response->headers); |
| 3767 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3768 | EXPECT_EQ(407, response->headers->response_code()); |
| 3769 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3771 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3772 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3774 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3775 | ASSERT_TRUE(response); |
| 3776 | ASSERT_TRUE(response->headers); |
| 3777 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3778 | EXPECT_EQ(200, response->headers->response_code()); |
| 3779 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3780 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3781 | EXPECT_EQ("hello", body); |
| 3782 | } |
| 3783 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3784 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3785 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3786 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3787 | HttpRequestInfo request; |
| 3788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3789 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3790 | request.traffic_annotation = |
| 3791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3792 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3793 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3794 | session_deps_.proxy_resolution_service = |
| 3795 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3796 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3800 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3801 | // Since we have proxy, should try to establish tunnel. |
| 3802 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3803 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3804 | "Host: www.example.org:443\r\n" |
| 3805 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3806 | }; |
| 3807 | |
| 3808 | // The proxy responds to the connect with a 407. |
| 3809 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3810 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3811 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3812 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3813 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3814 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3815 | }; |
| 3816 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3817 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3818 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3819 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3821 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3822 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3823 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3825 | |
| 3826 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3829 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3830 | ASSERT_TRUE(response); |
| 3831 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3832 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3833 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3834 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3835 | |
| 3836 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3837 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3838 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3839 | |
| 3840 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3841 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3842 | } |
| 3843 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3844 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3845 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3846 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3847 | HttpRequestInfo request; |
| 3848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3849 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3850 | request.traffic_annotation = |
| 3851 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3852 | |
| 3853 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3854 | session_deps_.proxy_resolution_service = |
| 3855 | ProxyResolutionService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3856 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3858 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3860 | |
| 3861 | // Since we have proxy, should try to establish tunnel. |
| 3862 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3863 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3864 | "Host: www.example.org:443\r\n" |
| 3865 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3866 | }; |
| 3867 | |
| 3868 | // The proxy responds to the connect with a 407. |
| 3869 | MockRead data_reads[] = { |
| 3870 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3871 | MockRead("X-Foo: bar\r\n"), |
| 3872 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3873 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3874 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3875 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3876 | }; |
| 3877 | |
| 3878 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3879 | arraysize(data_writes)); |
| 3880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3881 | |
| 3882 | TestCompletionCallback callback; |
| 3883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3886 | |
| 3887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3888 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3891 | ASSERT_TRUE(response); |
| 3892 | ASSERT_TRUE(response->headers); |
| 3893 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3894 | EXPECT_EQ(407, response->headers->response_code()); |
| 3895 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3896 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3897 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3898 | |
| 3899 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3900 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3901 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3902 | |
| 3903 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3904 | session->CloseAllConnections(); |
| 3905 | } |
| 3906 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3907 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3908 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3909 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3910 | HttpRequestInfo request; |
| 3911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3912 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3913 | request.traffic_annotation = |
| 3914 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3915 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3916 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3919 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3920 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3921 | MockWrite( |
| 3922 | "GET / HTTP/1.1\r\n" |
| 3923 | "Host: www.example.org\r\n" |
| 3924 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3925 | }; |
| 3926 | |
| 3927 | MockRead data_reads1[] = { |
| 3928 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3929 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3930 | // Large content-length -- won't matter, as connection will be reset. |
| 3931 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3932 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3933 | }; |
| 3934 | |
| 3935 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3936 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3937 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3938 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3939 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3940 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3941 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3943 | |
| 3944 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3945 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3946 | } |
| 3947 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3948 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3949 | // through a non-authenticating proxy. The request should fail with |
| 3950 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3951 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3952 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3953 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3954 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3955 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3956 | HttpRequestInfo request; |
| 3957 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3958 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3959 | request.traffic_annotation = |
| 3960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3961 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3962 | session_deps_.proxy_resolution_service = |
| 3963 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3964 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3965 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3967 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3968 | // Since we have proxy, should try to establish tunnel. |
| 3969 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3970 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3971 | "Host: www.example.org:443\r\n" |
| 3972 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3973 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3974 | MockWrite("GET / HTTP/1.1\r\n" |
| 3975 | "Host: www.example.org\r\n" |
| 3976 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3977 | }; |
| 3978 | |
| 3979 | MockRead data_reads1[] = { |
| 3980 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3981 | |
| 3982 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3983 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3984 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3985 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3986 | }; |
| 3987 | |
| 3988 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3989 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3991 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3992 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3994 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3996 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3998 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4000 | |
| 4001 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4002 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4003 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4004 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4005 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4006 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4007 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4008 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4009 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4010 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4011 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4012 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4013 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4014 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4015 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4016 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4017 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4018 | HttpRequestInfo request; |
| 4019 | request.method = "GET"; |
| 4020 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4021 | request.traffic_annotation = |
| 4022 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4023 | |
| 4024 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4025 | session_deps_.proxy_resolution_service = |
| 4026 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4027 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4028 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4029 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4030 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4031 | mock_handler->set_allows_default_credentials(true); |
| 4032 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4033 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4034 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4035 | |
| 4036 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4037 | NetLog net_log; |
| 4038 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4039 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4040 | |
| 4041 | // Since we have proxy, should try to establish tunnel. |
| 4042 | MockWrite data_writes1[] = { |
| 4043 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4044 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4045 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4046 | }; |
| 4047 | |
| 4048 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4049 | // connection. |
| 4050 | MockRead data_reads1[] = { |
| 4051 | // No credentials. |
| 4052 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4053 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4054 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4055 | }; |
| 4056 | |
| 4057 | // Since the first connection couldn't be reused, need to establish another |
| 4058 | // once given credentials. |
| 4059 | MockWrite data_writes2[] = { |
| 4060 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4061 | // be issuing -- the final header line contains the credentials. |
| 4062 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4063 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | "Proxy-Connection: keep-alive\r\n" |
| 4065 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4066 | |
| 4067 | MockWrite("GET / HTTP/1.1\r\n" |
| 4068 | "Host: www.example.org\r\n" |
| 4069 | "Connection: keep-alive\r\n\r\n"), |
| 4070 | }; |
| 4071 | |
| 4072 | MockRead data_reads2[] = { |
| 4073 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4074 | |
| 4075 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4076 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4077 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4078 | MockRead(SYNCHRONOUS, "hello"), |
| 4079 | }; |
| 4080 | |
| 4081 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4082 | data_writes1, arraysize(data_writes1)); |
| 4083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4084 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4085 | data_writes2, arraysize(data_writes2)); |
| 4086 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4087 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4089 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4090 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4091 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4092 | |
| 4093 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4094 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4095 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4096 | |
| 4097 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4098 | ASSERT_TRUE(response); |
| 4099 | ASSERT_TRUE(response->headers); |
| 4100 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4101 | EXPECT_EQ(407, response->headers->response_code()); |
| 4102 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4103 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4104 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4105 | |
| 4106 | LoadTimingInfo load_timing_info; |
| 4107 | // CONNECT requests and responses are handled at the connect job level, so |
| 4108 | // the transaction does not yet have a connection. |
| 4109 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4110 | |
| 4111 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4112 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4113 | response = trans->GetResponseInfo(); |
| 4114 | ASSERT_TRUE(response); |
| 4115 | ASSERT_TRUE(response->headers); |
| 4116 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4117 | EXPECT_EQ(200, response->headers->response_code()); |
| 4118 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4119 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4120 | |
| 4121 | // The password prompt info should not be set. |
| 4122 | EXPECT_FALSE(response->auth_challenge); |
| 4123 | |
| 4124 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4125 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4126 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4127 | |
| 4128 | trans.reset(); |
| 4129 | session->CloseAllConnections(); |
| 4130 | } |
| 4131 | |
| 4132 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4133 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4134 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4135 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4136 | HttpRequestInfo request; |
| 4137 | request.method = "GET"; |
| 4138 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4139 | request.traffic_annotation = |
| 4140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4141 | |
| 4142 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4143 | session_deps_.proxy_resolution_service = |
| 4144 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4145 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4146 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4147 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4148 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4149 | mock_handler->set_allows_default_credentials(true); |
| 4150 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4151 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4152 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4153 | |
| 4154 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4155 | NetLog net_log; |
| 4156 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4157 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4158 | |
| 4159 | // Should try to establish tunnel. |
| 4160 | MockWrite data_writes1[] = { |
| 4161 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4162 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4163 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4164 | |
| 4165 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4166 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4167 | "Proxy-Connection: keep-alive\r\n" |
| 4168 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4169 | }; |
| 4170 | |
| 4171 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4172 | // connection. |
| 4173 | MockRead data_reads1[] = { |
| 4174 | // No credentials. |
| 4175 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4176 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4177 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4178 | }; |
| 4179 | |
| 4180 | // Since the first connection was closed, need to establish another once given |
| 4181 | // credentials. |
| 4182 | MockWrite data_writes2[] = { |
| 4183 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4184 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4185 | "Proxy-Connection: keep-alive\r\n" |
| 4186 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4187 | |
| 4188 | MockWrite("GET / HTTP/1.1\r\n" |
| 4189 | "Host: www.example.org\r\n" |
| 4190 | "Connection: keep-alive\r\n\r\n"), |
| 4191 | }; |
| 4192 | |
| 4193 | MockRead data_reads2[] = { |
| 4194 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4195 | |
| 4196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4197 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4198 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4199 | MockRead(SYNCHRONOUS, "hello"), |
| 4200 | }; |
| 4201 | |
| 4202 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4203 | data_writes1, arraysize(data_writes1)); |
| 4204 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4205 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4206 | data_writes2, arraysize(data_writes2)); |
| 4207 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4208 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4209 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4210 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4211 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4212 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4213 | |
| 4214 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4215 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4216 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4217 | |
| 4218 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4219 | ASSERT_TRUE(response); |
| 4220 | ASSERT_TRUE(response->headers); |
| 4221 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4222 | EXPECT_EQ(407, response->headers->response_code()); |
| 4223 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4224 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4225 | EXPECT_FALSE(response->auth_challenge); |
| 4226 | |
| 4227 | LoadTimingInfo load_timing_info; |
| 4228 | // CONNECT requests and responses are handled at the connect job level, so |
| 4229 | // the transaction does not yet have a connection. |
| 4230 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4231 | |
| 4232 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4233 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4234 | |
| 4235 | response = trans->GetResponseInfo(); |
| 4236 | ASSERT_TRUE(response); |
| 4237 | ASSERT_TRUE(response->headers); |
| 4238 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4239 | EXPECT_EQ(200, response->headers->response_code()); |
| 4240 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4241 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4242 | |
| 4243 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4244 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4245 | |
| 4246 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4247 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4248 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4249 | |
| 4250 | trans.reset(); |
| 4251 | session->CloseAllConnections(); |
| 4252 | } |
| 4253 | |
| 4254 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4255 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4256 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4257 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4259 | HttpRequestInfo request; |
| 4260 | request.method = "GET"; |
| 4261 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4262 | request.traffic_annotation = |
| 4263 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4264 | |
| 4265 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4266 | session_deps_.proxy_resolution_service = |
| 4267 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4268 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4269 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4271 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4272 | mock_handler->set_allows_default_credentials(true); |
| 4273 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4274 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4275 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4276 | |
| 4277 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4278 | NetLog net_log; |
| 4279 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4280 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4281 | |
| 4282 | // Should try to establish tunnel. |
| 4283 | MockWrite data_writes1[] = { |
| 4284 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4285 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4287 | |
| 4288 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4289 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | "Proxy-Connection: keep-alive\r\n" |
| 4291 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4292 | }; |
| 4293 | |
| 4294 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4295 | // second request is sent. |
| 4296 | MockRead data_reads1[] = { |
| 4297 | // No credentials. |
| 4298 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4299 | MockRead("Content-Length: 0\r\n"), |
| 4300 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4301 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4302 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4303 | }; |
| 4304 | |
| 4305 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4306 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4307 | // request. |
| 4308 | MockWrite data_writes2[] = { |
| 4309 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4310 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4311 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4312 | }; |
| 4313 | |
| 4314 | // The proxy, having had more than enough of us, just hangs up. |
| 4315 | MockRead data_reads2[] = { |
| 4316 | // No credentials. |
| 4317 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4318 | }; |
| 4319 | |
| 4320 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4321 | data_writes1, arraysize(data_writes1)); |
| 4322 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4323 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4324 | data_writes2, arraysize(data_writes2)); |
| 4325 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4326 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4327 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4328 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4329 | |
| 4330 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4331 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4332 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4333 | |
| 4334 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4335 | ASSERT_TRUE(response); |
| 4336 | ASSERT_TRUE(response->headers); |
| 4337 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4338 | EXPECT_EQ(407, response->headers->response_code()); |
| 4339 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4340 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4341 | EXPECT_FALSE(response->auth_challenge); |
| 4342 | |
| 4343 | LoadTimingInfo load_timing_info; |
| 4344 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4345 | |
| 4346 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4347 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4348 | |
| 4349 | trans.reset(); |
| 4350 | session->CloseAllConnections(); |
| 4351 | } |
| 4352 | |
| 4353 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4354 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4355 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4356 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4357 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4358 | HttpRequestInfo request; |
| 4359 | request.method = "GET"; |
| 4360 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4361 | request.traffic_annotation = |
| 4362 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4363 | |
| 4364 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4365 | session_deps_.proxy_resolution_service = |
| 4366 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4367 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4368 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4369 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4370 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4371 | mock_handler->set_allows_default_credentials(true); |
| 4372 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4373 | HttpAuth::AUTH_PROXY); |
| 4374 | // Add another handler for the second challenge. It supports default |
| 4375 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4376 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4377 | mock_handler->set_allows_default_credentials(true); |
| 4378 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4379 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4380 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4381 | |
| 4382 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4383 | NetLog net_log; |
| 4384 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4385 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4386 | |
| 4387 | // Should try to establish tunnel. |
| 4388 | MockWrite data_writes1[] = { |
| 4389 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4390 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4391 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4392 | }; |
| 4393 | |
| 4394 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4395 | // connection. |
| 4396 | MockRead data_reads1[] = { |
| 4397 | // No credentials. |
| 4398 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4399 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4400 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4401 | }; |
| 4402 | |
| 4403 | // Since the first connection was closed, need to establish another once given |
| 4404 | // credentials. |
| 4405 | MockWrite data_writes2[] = { |
| 4406 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4407 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4408 | "Proxy-Connection: keep-alive\r\n" |
| 4409 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4410 | }; |
| 4411 | |
| 4412 | MockRead data_reads2[] = { |
| 4413 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4414 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4415 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4416 | }; |
| 4417 | |
| 4418 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4419 | data_writes1, arraysize(data_writes1)); |
| 4420 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4421 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4422 | data_writes2, arraysize(data_writes2)); |
| 4423 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4424 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4426 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4427 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4428 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4429 | |
| 4430 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4431 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4432 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4433 | |
| 4434 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4435 | ASSERT_TRUE(response); |
| 4436 | ASSERT_TRUE(response->headers); |
| 4437 | EXPECT_EQ(407, response->headers->response_code()); |
| 4438 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4439 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4440 | EXPECT_FALSE(response->auth_challenge); |
| 4441 | |
| 4442 | LoadTimingInfo load_timing_info; |
| 4443 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4444 | |
| 4445 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4446 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4447 | response = trans->GetResponseInfo(); |
| 4448 | ASSERT_TRUE(response); |
| 4449 | ASSERT_TRUE(response->headers); |
| 4450 | EXPECT_EQ(407, response->headers->response_code()); |
| 4451 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4452 | EXPECT_TRUE(response->auth_challenge); |
| 4453 | |
| 4454 | trans.reset(); |
| 4455 | session->CloseAllConnections(); |
| 4456 | } |
| 4457 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4458 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4459 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4460 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4461 | // authentication handshake can continue with the same scheme but with a |
| 4462 | // different identity. |
| 4463 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4464 | HttpRequestInfo request; |
| 4465 | request.method = "GET"; |
| 4466 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4467 | request.traffic_annotation = |
| 4468 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4469 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4470 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4471 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4472 | |
| 4473 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4474 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4475 | mock_handler->set_allows_default_credentials(true); |
| 4476 | mock_handler->set_allows_explicit_credentials(true); |
| 4477 | mock_handler->set_connection_based(true); |
| 4478 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4479 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4480 | HttpAuth::AUTH_SERVER); |
| 4481 | |
| 4482 | // Add another handler for the second challenge. It supports default |
| 4483 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4484 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4485 | mock_handler->set_allows_default_credentials(true); |
| 4486 | mock_handler->set_allows_explicit_credentials(true); |
| 4487 | mock_handler->set_connection_based(true); |
| 4488 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4489 | HttpAuth::AUTH_SERVER); |
| 4490 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4491 | |
| 4492 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4493 | |
| 4494 | MockWrite data_writes1[] = { |
| 4495 | MockWrite("GET / HTTP/1.1\r\n" |
| 4496 | "Host: www.example.org\r\n" |
| 4497 | "Connection: keep-alive\r\n\r\n"), |
| 4498 | }; |
| 4499 | |
| 4500 | MockRead data_reads1[] = { |
| 4501 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4502 | "WWW-Authenticate: Mock\r\n" |
| 4503 | "Connection: keep-alive\r\n\r\n"), |
| 4504 | }; |
| 4505 | |
| 4506 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4507 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4508 | // transaction procceds without an authorization header. |
| 4509 | MockWrite data_writes2[] = { |
| 4510 | MockWrite("GET / HTTP/1.1\r\n" |
| 4511 | "Host: www.example.org\r\n" |
| 4512 | "Connection: keep-alive\r\n\r\n"), |
| 4513 | }; |
| 4514 | |
| 4515 | MockRead data_reads2[] = { |
| 4516 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4517 | "WWW-Authenticate: Mock\r\n" |
| 4518 | "Connection: keep-alive\r\n\r\n"), |
| 4519 | }; |
| 4520 | |
| 4521 | MockWrite data_writes3[] = { |
| 4522 | MockWrite("GET / HTTP/1.1\r\n" |
| 4523 | "Host: www.example.org\r\n" |
| 4524 | "Connection: keep-alive\r\n" |
| 4525 | "Authorization: auth_token\r\n\r\n"), |
| 4526 | }; |
| 4527 | |
| 4528 | MockRead data_reads3[] = { |
| 4529 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4530 | "Content-Length: 5\r\n" |
| 4531 | "Content-Type: text/plain\r\n" |
| 4532 | "Connection: keep-alive\r\n\r\n" |
| 4533 | "Hello"), |
| 4534 | }; |
| 4535 | |
| 4536 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4537 | data_writes1, arraysize(data_writes1)); |
| 4538 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4539 | |
| 4540 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4541 | data_writes2, arraysize(data_writes2)); |
| 4542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4543 | |
| 4544 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4545 | data_writes3, arraysize(data_writes3)); |
| 4546 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4547 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4548 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4549 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4550 | |
| 4551 | TestCompletionCallback callback; |
| 4552 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4553 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4554 | |
| 4555 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4556 | ASSERT_TRUE(response); |
| 4557 | ASSERT_TRUE(response->headers); |
| 4558 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4559 | |
| 4560 | // The following three tests assert that an authentication challenge was |
| 4561 | // received and that the stack is ready to respond to the challenge using |
| 4562 | // ambient credentials. |
| 4563 | EXPECT_EQ(401, response->headers->response_code()); |
| 4564 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4565 | EXPECT_FALSE(response->auth_challenge); |
| 4566 | |
| 4567 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4568 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4569 | response = trans->GetResponseInfo(); |
| 4570 | ASSERT_TRUE(response); |
| 4571 | ASSERT_TRUE(response->headers); |
| 4572 | |
| 4573 | // The following three tests assert that an authentication challenge was |
| 4574 | // received and that the stack needs explicit credentials before it is ready |
| 4575 | // to respond to the challenge. |
| 4576 | EXPECT_EQ(401, response->headers->response_code()); |
| 4577 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4578 | EXPECT_TRUE(response->auth_challenge); |
| 4579 | |
| 4580 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4581 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4582 | response = trans->GetResponseInfo(); |
| 4583 | ASSERT_TRUE(response); |
| 4584 | ASSERT_TRUE(response->headers); |
| 4585 | EXPECT_EQ(200, response->headers->response_code()); |
| 4586 | |
| 4587 | trans.reset(); |
| 4588 | session->CloseAllConnections(); |
| 4589 | } |
| 4590 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4591 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4592 | // schemes, based on the path of the URL being requests. |
| 4593 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4594 | public: |
| 4595 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4596 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4597 | |
| 4598 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4599 | |
| 4600 | static HostPortPair ProxyHostPortPair() { |
| 4601 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4602 | } |
| 4603 | |
| 4604 | // ProxyResolver implementation. |
| 4605 | int GetProxyForURL(const GURL& url, |
| 4606 | ProxyInfo* results, |
| 4607 | const CompletionCallback& callback, |
| 4608 | std::unique_ptr<Request>* request, |
| 4609 | const NetLogWithSource& /*net_log*/) override { |
| 4610 | *results = ProxyInfo(); |
| 4611 | if (url.path() == "/socks4") { |
| 4612 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4613 | return OK; |
| 4614 | } |
| 4615 | if (url.path() == "/socks5") { |
| 4616 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4617 | return OK; |
| 4618 | } |
| 4619 | if (url.path() == "/http") { |
| 4620 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4621 | return OK; |
| 4622 | } |
| 4623 | if (url.path() == "/https") { |
| 4624 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4625 | return OK; |
| 4626 | } |
| 4627 | NOTREACHED(); |
| 4628 | return ERR_NOT_IMPLEMENTED; |
| 4629 | } |
| 4630 | |
| 4631 | private: |
| 4632 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4633 | }; |
| 4634 | |
| 4635 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4636 | : public ProxyResolverFactory { |
| 4637 | public: |
| 4638 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4639 | : ProxyResolverFactory(false) {} |
| 4640 | |
| 4641 | int CreateProxyResolver( |
| 4642 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 4643 | std::unique_ptr<ProxyResolver>* resolver, |
| 4644 | const CompletionCallback& callback, |
| 4645 | std::unique_ptr<Request>* request) override { |
| 4646 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4647 | return OK; |
| 4648 | } |
| 4649 | |
| 4650 | private: |
| 4651 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4652 | }; |
| 4653 | |
| 4654 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4655 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4656 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4657 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4658 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4659 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4660 | std::make_unique<ProxyConfigServiceFixed>( |
| 4661 | ProxyConfig::CreateAutoDetect()), |
| 4662 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4663 | nullptr); |
| 4664 | |
| 4665 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4666 | |
| 4667 | MockWrite socks_writes[] = { |
| 4668 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4669 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4670 | MockWrite(SYNCHRONOUS, |
| 4671 | "GET /socks4 HTTP/1.1\r\n" |
| 4672 | "Host: test\r\n" |
| 4673 | "Connection: keep-alive\r\n\r\n"), |
| 4674 | }; |
| 4675 | MockRead socks_reads[] = { |
| 4676 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4677 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4678 | "Connection: keep-alive\r\n" |
| 4679 | "Content-Length: 15\r\n\r\n" |
| 4680 | "SOCKS4 Response"), |
| 4681 | }; |
| 4682 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4683 | socks_writes, arraysize(socks_writes)); |
| 4684 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4685 | |
| 4686 | const char kSOCKS5Request[] = { |
| 4687 | 0x05, // Version |
| 4688 | 0x01, // Command (CONNECT) |
| 4689 | 0x00, // Reserved |
| 4690 | 0x03, // Address type (DOMAINNAME) |
| 4691 | 0x04, // Length of domain (4) |
| 4692 | 't', 'e', 's', 't', // Domain string |
| 4693 | 0x00, 0x50, // 16-bit port (80) |
| 4694 | }; |
| 4695 | MockWrite socks5_writes[] = { |
| 4696 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4697 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4698 | MockWrite(SYNCHRONOUS, |
| 4699 | "GET /socks5 HTTP/1.1\r\n" |
| 4700 | "Host: test\r\n" |
| 4701 | "Connection: keep-alive\r\n\r\n"), |
| 4702 | }; |
| 4703 | MockRead socks5_reads[] = { |
| 4704 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4705 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4706 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4707 | "Connection: keep-alive\r\n" |
| 4708 | "Content-Length: 15\r\n\r\n" |
| 4709 | "SOCKS5 Response"), |
| 4710 | }; |
| 4711 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4712 | socks5_writes, arraysize(socks5_writes)); |
| 4713 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4714 | |
| 4715 | MockWrite http_writes[] = { |
| 4716 | MockWrite(SYNCHRONOUS, |
| 4717 | "GET http://test/http HTTP/1.1\r\n" |
| 4718 | "Host: test\r\n" |
| 4719 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4720 | }; |
| 4721 | MockRead http_reads[] = { |
| 4722 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4723 | "Proxy-Connection: keep-alive\r\n" |
| 4724 | "Content-Length: 13\r\n\r\n" |
| 4725 | "HTTP Response"), |
| 4726 | }; |
| 4727 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4728 | http_writes, arraysize(http_writes)); |
| 4729 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4730 | |
| 4731 | MockWrite https_writes[] = { |
| 4732 | MockWrite(SYNCHRONOUS, |
| 4733 | "GET http://test/https HTTP/1.1\r\n" |
| 4734 | "Host: test\r\n" |
| 4735 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4736 | }; |
| 4737 | MockRead https_reads[] = { |
| 4738 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4739 | "Proxy-Connection: keep-alive\r\n" |
| 4740 | "Content-Length: 14\r\n\r\n" |
| 4741 | "HTTPS Response"), |
| 4742 | }; |
| 4743 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4744 | https_writes, arraysize(https_writes)); |
| 4745 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4746 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4748 | |
| 4749 | struct TestCase { |
| 4750 | GURL url; |
| 4751 | std::string expected_response; |
| 4752 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4753 | // after the test. |
| 4754 | int expected_idle_socks_sockets; |
| 4755 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4756 | // the test. |
| 4757 | int expected_idle_http_sockets; |
| 4758 | } const kTestCases[] = { |
| 4759 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4760 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4761 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4762 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4763 | }; |
| 4764 | |
| 4765 | for (const auto& test_case : kTestCases) { |
| 4766 | HttpRequestInfo request; |
| 4767 | request.method = "GET"; |
| 4768 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4769 | request.traffic_annotation = |
| 4770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4771 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4772 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4773 | session.get()); |
| 4774 | TestCompletionCallback callback; |
| 4775 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4776 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4777 | |
| 4778 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4779 | ASSERT_TRUE(response); |
| 4780 | ASSERT_TRUE(response->headers); |
| 4781 | EXPECT_EQ(200, response->headers->response_code()); |
| 4782 | std::string response_data; |
| 4783 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4784 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4785 | |
| 4786 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4787 | // the next requests. |
| 4788 | trans.reset(); |
| 4789 | base::RunLoop().RunUntilIdle(); |
| 4790 | |
| 4791 | // Check the number of idle sockets in the pool, to make sure that used |
| 4792 | // sockets are indeed being returned to the socket pool. If each request |
| 4793 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4794 | // pass. |
| 4795 | EXPECT_EQ( |
| 4796 | test_case.expected_idle_socks_sockets, |
| 4797 | session |
| 4798 | ->GetSocketPoolForSOCKSProxy( |
| 4799 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4800 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4801 | ->IdleSocketCount()); |
| 4802 | EXPECT_EQ( |
| 4803 | test_case.expected_idle_http_sockets, |
| 4804 | session |
| 4805 | ->GetSocketPoolForHTTPProxy( |
| 4806 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4807 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4808 | ->IdleSocketCount()); |
| 4809 | } |
| 4810 | } |
| 4811 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4812 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4813 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4814 | HttpRequestInfo request1; |
| 4815 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4816 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4817 | request1.traffic_annotation = |
| 4818 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4819 | |
| 4820 | HttpRequestInfo request2; |
| 4821 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4822 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4823 | request2.traffic_annotation = |
| 4824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4825 | |
| 4826 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4827 | session_deps_.proxy_resolution_service = |
| 4828 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4829 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4830 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4832 | |
| 4833 | // Since we have proxy, should try to establish tunnel. |
| 4834 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4835 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4836 | "Host: www.example.org:443\r\n" |
| 4837 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4838 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4839 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4840 | "Host: www.example.org\r\n" |
| 4841 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4842 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4843 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4844 | "Host: www.example.org\r\n" |
| 4845 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4846 | }; |
| 4847 | |
| 4848 | // The proxy responds to the connect with a 407, using a persistent |
| 4849 | // connection. |
| 4850 | MockRead data_reads1[] = { |
| 4851 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4852 | |
| 4853 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4854 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4855 | MockRead(SYNCHRONOUS, "1"), |
| 4856 | |
| 4857 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4858 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4859 | MockRead(SYNCHRONOUS, "22"), |
| 4860 | }; |
| 4861 | |
| 4862 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4863 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4864 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4865 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4866 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4867 | |
| 4868 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4869 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4870 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4871 | |
| 4872 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4874 | |
| 4875 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4876 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4877 | |
| 4878 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4879 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4880 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4881 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4882 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4883 | |
| 4884 | LoadTimingInfo load_timing_info1; |
| 4885 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4886 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4887 | |
| 4888 | trans1.reset(); |
| 4889 | |
| 4890 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4891 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4892 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4893 | |
| 4894 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4896 | |
| 4897 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4898 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4899 | |
| 4900 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4901 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4902 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4903 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4904 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4905 | |
| 4906 | LoadTimingInfo load_timing_info2; |
| 4907 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4908 | TestLoadTimingReused(load_timing_info2); |
| 4909 | |
| 4910 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4911 | |
| 4912 | trans2.reset(); |
| 4913 | session->CloseAllConnections(); |
| 4914 | } |
| 4915 | |
| 4916 | // 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] | 4917 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4918 | HttpRequestInfo request1; |
| 4919 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4920 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4921 | request1.traffic_annotation = |
| 4922 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4923 | |
| 4924 | HttpRequestInfo request2; |
| 4925 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4926 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4927 | request2.traffic_annotation = |
| 4928 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4929 | |
| 4930 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4931 | session_deps_.proxy_resolution_service = |
| 4932 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4933 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4934 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4936 | |
| 4937 | // Since we have proxy, should try to establish tunnel. |
| 4938 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4939 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4940 | "Host: www.example.org:443\r\n" |
| 4941 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4942 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4943 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4944 | "Host: www.example.org\r\n" |
| 4945 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4946 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4947 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4948 | "Host: www.example.org\r\n" |
| 4949 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4950 | }; |
| 4951 | |
| 4952 | // The proxy responds to the connect with a 407, using a persistent |
| 4953 | // connection. |
| 4954 | MockRead data_reads1[] = { |
| 4955 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4956 | |
| 4957 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4958 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4959 | MockRead(SYNCHRONOUS, "1"), |
| 4960 | |
| 4961 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4962 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4963 | MockRead(SYNCHRONOUS, "22"), |
| 4964 | }; |
| 4965 | |
| 4966 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4967 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4968 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4969 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4971 | |
| 4972 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4973 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4974 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4975 | |
| 4976 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4978 | |
| 4979 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4980 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4981 | |
| 4982 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4983 | ASSERT_TRUE(response1); |
| 4984 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4985 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4986 | |
| 4987 | LoadTimingInfo load_timing_info1; |
| 4988 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4989 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4990 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4991 | |
| 4992 | trans1.reset(); |
| 4993 | |
| 4994 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4995 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4996 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4997 | |
| 4998 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5000 | |
| 5001 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5002 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5003 | |
| 5004 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5005 | ASSERT_TRUE(response2); |
| 5006 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5007 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5008 | |
| 5009 | LoadTimingInfo load_timing_info2; |
| 5010 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5011 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5012 | |
| 5013 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5014 | |
| 5015 | trans2.reset(); |
| 5016 | session->CloseAllConnections(); |
| 5017 | } |
| 5018 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5019 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5020 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5021 | HttpRequestInfo request; |
| 5022 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5023 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5024 | request.traffic_annotation = |
| 5025 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5026 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5027 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5028 | session_deps_.proxy_resolution_service = |
| 5029 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5030 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5031 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5033 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5034 | // Since we have proxy, should use full url |
| 5035 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5036 | MockWrite( |
| 5037 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5038 | "Host: www.example.org\r\n" |
| 5039 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5040 | }; |
| 5041 | |
| 5042 | MockRead data_reads1[] = { |
| 5043 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5044 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5045 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5046 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5047 | }; |
| 5048 | |
| 5049 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5050 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5051 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5052 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5054 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5055 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5057 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5059 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5061 | |
| 5062 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5063 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5064 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5065 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5066 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5067 | TestLoadTimingNotReused(load_timing_info, |
| 5068 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5070 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5071 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5072 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5073 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5074 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5075 | EXPECT_EQ(200, response->headers->response_code()); |
| 5076 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5077 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5078 | |
| 5079 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5080 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5081 | } |
| 5082 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5083 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5084 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5085 | HttpRequestInfo request; |
| 5086 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5087 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5088 | request.traffic_annotation = |
| 5089 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5090 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5091 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5092 | session_deps_.proxy_resolution_service = |
| 5093 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5094 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5095 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5096 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5097 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5098 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5099 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5100 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5101 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5102 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5103 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5104 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5105 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5106 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5107 | }; |
| 5108 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5109 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5110 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5111 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5112 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5113 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5114 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5116 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5117 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5121 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5123 | |
| 5124 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5125 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5126 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5127 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5128 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5129 | TestLoadTimingNotReused(load_timing_info, |
| 5130 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5132 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5133 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5134 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5135 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5136 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5137 | |
| 5138 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5139 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5140 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5141 | } |
| 5142 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5143 | // Verifies that a session which races and wins against the owning transaction |
| 5144 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5145 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5146 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5147 | HttpRequestInfo request; |
| 5148 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5149 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5150 | request.traffic_annotation = |
| 5151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5152 | |
| 5153 | // Configure SPDY proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5154 | session_deps_.proxy_resolution_service = |
| 5155 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5156 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5157 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5159 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5160 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5161 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5162 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5163 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5164 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5165 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5166 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5167 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5168 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5169 | }; |
| 5170 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5171 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5172 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5173 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5174 | |
| 5175 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5176 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5178 | |
| 5179 | TestCompletionCallback callback1; |
| 5180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5182 | |
| 5183 | // Stall the hostname resolution begun by the transaction. |
| 5184 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5185 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5187 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5188 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5189 | |
| 5190 | // Race a session to the proxy, which completes first. |
| 5191 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5192 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5193 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5194 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5195 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5196 | |
| 5197 | // Unstall the resolution begun by the transaction. |
| 5198 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5199 | session_deps_.host_resolver->ResolveAllPending(); |
| 5200 | |
| 5201 | EXPECT_FALSE(callback1.have_result()); |
| 5202 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5205 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5206 | ASSERT_TRUE(response); |
| 5207 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5208 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5209 | |
| 5210 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5211 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5212 | EXPECT_EQ(kUploadData, response_data); |
| 5213 | } |
| 5214 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5215 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5216 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5217 | HttpRequestInfo request; |
| 5218 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5219 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5220 | request.traffic_annotation = |
| 5221 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5222 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5223 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5224 | session_deps_.proxy_resolution_service = |
| 5225 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5226 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5227 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5229 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5230 | // The first request will be a bare GET, the second request will be a |
| 5231 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5232 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5233 | SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5234 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5235 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5236 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5237 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5238 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5239 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5240 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5241 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5242 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5243 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5244 | }; |
| 5245 | |
| 5246 | // The first response is a 407 proxy authentication challenge, and the second |
| 5247 | // response will be a 200 response since the second request includes a valid |
| 5248 | // Authorization header. |
| 5249 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5250 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5251 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5252 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5253 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5254 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5255 | SpdySerializedFrame body_authentication( |
| 5256 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5257 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5258 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5259 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5260 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5261 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5262 | CreateMockRead(resp_data, 4), |
| 5263 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5264 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5265 | }; |
| 5266 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5267 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5268 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5270 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5271 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5272 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5275 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5279 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
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 = callback1.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 = 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); |
| 5288 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5289 | EXPECT_EQ(407, response->headers->response_code()); |
| 5290 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5291 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5293 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5295 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5297 | |
| 5298 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5299 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5301 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5302 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5303 | ASSERT_TRUE(response_restart); |
| 5304 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5305 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5306 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5307 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5308 | } |
| 5309 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5310 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5311 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5312 | HttpRequestInfo request; |
| 5313 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5314 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5315 | request.traffic_annotation = |
| 5316 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5317 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5318 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5319 | session_deps_.proxy_resolution_service = |
| 5320 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5321 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5322 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5323 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5326 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5327 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5328 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5329 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5330 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5332 | const char get[] = |
| 5333 | "GET / HTTP/1.1\r\n" |
| 5334 | "Host: www.example.org\r\n" |
| 5335 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5336 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5337 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5338 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5339 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5340 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5342 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5343 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5344 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5345 | SpdySerializedFrame window_update( |
| 5346 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5347 | |
| 5348 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5349 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5350 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5351 | }; |
| 5352 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5353 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5354 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5355 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5356 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5357 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5358 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5359 | }; |
| 5360 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5361 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5362 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5363 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5364 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5365 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5366 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5368 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5371 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5373 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5375 | |
| 5376 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5377 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5378 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5379 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5380 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5381 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5383 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5384 | ASSERT_TRUE(response); |
| 5385 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5386 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5387 | |
| 5388 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5389 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5390 | EXPECT_EQ("1234567890", response_data); |
| 5391 | } |
| 5392 | |
| 5393 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5394 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5395 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5396 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5397 | HttpRequestInfo request; |
| 5398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5399 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5400 | request.traffic_annotation = |
| 5401 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5402 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5403 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5404 | session_deps_.proxy_resolution_service = |
| 5405 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5406 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5411 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5412 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5413 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5414 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5415 | // fetch https://www.example.org/ via SPDY |
| 5416 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5417 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5418 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5419 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5420 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5421 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5422 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5423 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5424 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5425 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5426 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5427 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5428 | SpdySerializedFrame window_update_get_resp( |
| 5429 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5430 | SpdySerializedFrame window_update_body( |
| 5431 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5432 | |
| 5433 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5434 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5435 | CreateMockWrite(window_update_get_resp, 6), |
| 5436 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5437 | }; |
| 5438 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5439 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5440 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5441 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5442 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5443 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5444 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5445 | }; |
| 5446 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5447 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5448 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5449 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5450 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5451 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5452 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5453 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5454 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5455 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5458 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5460 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5462 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5463 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5464 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5465 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5466 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5467 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5468 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5469 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5470 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5471 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5472 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5475 | ASSERT_TRUE(response); |
| 5476 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5477 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5478 | |
| 5479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5480 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5481 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5482 | } |
| 5483 | |
| 5484 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5485 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5486 | HttpRequestInfo request; |
| 5487 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5488 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5489 | request.traffic_annotation = |
| 5490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5491 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5492 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5493 | session_deps_.proxy_resolution_service = |
| 5494 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5495 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5496 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5499 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5500 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5501 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5502 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5503 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5504 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5505 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5506 | |
| 5507 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5508 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5509 | }; |
| 5510 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5511 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5512 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5513 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5514 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5515 | }; |
| 5516 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5517 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5518 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5519 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5520 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5521 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5522 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5524 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5525 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5528 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5530 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5532 | |
| 5533 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5534 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5535 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5536 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5537 | } |
| 5538 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5539 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5540 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5541 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5542 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5543 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5544 | session_deps_.proxy_resolution_service = |
| 5545 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5546 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5547 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5548 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5549 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5550 | |
| 5551 | HttpRequestInfo request1; |
| 5552 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5553 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5554 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5555 | request1.traffic_annotation = |
| 5556 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5557 | |
| 5558 | HttpRequestInfo request2; |
| 5559 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5560 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5561 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5562 | request2.traffic_annotation = |
| 5563 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5564 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5565 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5566 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5567 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5568 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5569 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5570 | // Fetch https://www.example.org/ via HTTP. |
| 5571 | const char get1[] = |
| 5572 | "GET / HTTP/1.1\r\n" |
| 5573 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5574 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5575 | SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5576 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5577 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5578 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5579 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5580 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5581 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5582 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5583 | SpdySerializedFrame window_update( |
| 5584 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5585 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5586 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5587 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5588 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5589 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5590 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5591 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5592 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5593 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5594 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5595 | // Fetch https://mail.example.org/ via HTTP. |
| 5596 | const char get2[] = |
| 5597 | "GET / HTTP/1.1\r\n" |
| 5598 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5599 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5600 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5601 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5602 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5603 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5604 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5605 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5606 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5607 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5608 | |
| 5609 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5611 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5612 | }; |
| 5613 | |
| 5614 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5615 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5616 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5617 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5618 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5619 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5620 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5621 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5622 | }; |
| 5623 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5624 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5625 | arraysize(spdy_writes)); |
| 5626 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5627 | |
| 5628 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5629 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5631 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5632 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5633 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5635 | |
| 5636 | TestCompletionCallback callback; |
| 5637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5639 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5640 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5641 | |
| 5642 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5643 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5644 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5646 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5647 | ASSERT_TRUE(response); |
| 5648 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5649 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5650 | |
| 5651 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5652 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5653 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5654 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5656 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5657 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5658 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5659 | |
| 5660 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5661 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5662 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5663 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5664 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5665 | |
| 5666 | // The requests should have different IDs, since they each are using their own |
| 5667 | // separate stream. |
| 5668 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5670 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5671 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5675 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5677 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5678 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5679 | session_deps_.proxy_resolution_service = |
| 5680 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5681 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5682 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5683 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5684 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5685 | |
| 5686 | HttpRequestInfo request1; |
| 5687 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5688 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5689 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5690 | request1.traffic_annotation = |
| 5691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5692 | |
| 5693 | HttpRequestInfo request2; |
| 5694 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5695 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5696 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5697 | request2.traffic_annotation = |
| 5698 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5699 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5700 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5701 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5702 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5703 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[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/ via HTTP. |
| 5706 | const char get1[] = |
| 5707 | "GET / 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_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5711 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5712 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5713 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5714 | SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5715 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5716 | SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5717 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5718 | SpdySerializedFrame window_update( |
| 5719 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5720 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5721 | // Fetch https://www.example.org/2 via HTTP. |
| 5722 | const char get2[] = |
| 5723 | "GET /2 HTTP/1.1\r\n" |
| 5724 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5725 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5726 | SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5727 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5728 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5729 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5730 | SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5731 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5732 | SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5733 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5734 | |
| 5735 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5736 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5737 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5738 | }; |
| 5739 | |
| 5740 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5741 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5742 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5743 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5744 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5745 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5746 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5747 | }; |
| 5748 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5749 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5750 | arraysize(spdy_writes)); |
| 5751 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5752 | |
| 5753 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5754 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5756 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5758 | |
| 5759 | TestCompletionCallback callback; |
| 5760 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5761 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5762 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5763 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5765 | |
| 5766 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5767 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5768 | |
| 5769 | LoadTimingInfo load_timing_info; |
| 5770 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5771 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5772 | |
| 5773 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5774 | ASSERT_TRUE(response); |
| 5775 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5776 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5777 | |
| 5778 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5779 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5780 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5781 | trans.reset(); |
| 5782 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5783 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5784 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5785 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5787 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5789 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5790 | |
| 5791 | LoadTimingInfo load_timing_info2; |
| 5792 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5793 | TestLoadTimingReused(load_timing_info2); |
| 5794 | |
| 5795 | // The requests should have the same ID. |
| 5796 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5797 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5798 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5799 | } |
| 5800 | |
| 5801 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5802 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5803 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5804 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5805 | session_deps_.proxy_resolution_service = |
| 5806 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5807 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5808 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5809 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5810 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5811 | |
| 5812 | HttpRequestInfo request1; |
| 5813 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5814 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5815 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5816 | request1.traffic_annotation = |
| 5817 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5818 | |
| 5819 | HttpRequestInfo request2; |
| 5820 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5821 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5822 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5823 | request2.traffic_annotation = |
| 5824 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5825 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5826 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5827 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5828 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5829 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5830 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5831 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5832 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5833 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5834 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5835 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5836 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5837 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5838 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5839 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5840 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 5841 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5842 | |
| 5843 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5844 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5845 | }; |
| 5846 | |
| 5847 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5848 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5849 | CreateMockRead(body1, 2, ASYNC), |
| 5850 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5851 | CreateMockRead(body2, 5, ASYNC), |
| 5852 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5853 | }; |
| 5854 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5855 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5856 | arraysize(spdy_writes)); |
| 5857 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5858 | |
| 5859 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5860 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5862 | |
| 5863 | TestCompletionCallback callback; |
| 5864 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5865 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5866 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5867 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5868 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5869 | |
| 5870 | LoadTimingInfo load_timing_info; |
| 5871 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5872 | TestLoadTimingNotReused(load_timing_info, |
| 5873 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5874 | |
| 5875 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5876 | ASSERT_TRUE(response); |
| 5877 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5878 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5879 | |
| 5880 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5881 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5882 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5883 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5884 | // Delete the first request, so the second one can reuse the socket. |
| 5885 | trans.reset(); |
| 5886 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5887 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5888 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5889 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5890 | |
| 5891 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5892 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5893 | TestLoadTimingReused(load_timing_info2); |
| 5894 | |
| 5895 | // The requests should have the same ID. |
| 5896 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5898 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5899 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5900 | } |
| 5901 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5902 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5903 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5904 | HttpRequestInfo request; |
| 5905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5906 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5907 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5908 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5909 | request.traffic_annotation = |
| 5910 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5911 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5912 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5913 | session_deps_.proxy_resolution_service = |
| 5914 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5915 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5916 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5918 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5919 | // Since we have proxy, should use full url |
| 5920 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5921 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5922 | "Host: www.example.org\r\n" |
| 5923 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5925 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5926 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5927 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5928 | "Host: www.example.org\r\n" |
| 5929 | "Proxy-Connection: keep-alive\r\n" |
| 5930 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5931 | }; |
| 5932 | |
| 5933 | // The proxy responds to the GET with a 407, using a persistent |
| 5934 | // connection. |
| 5935 | MockRead data_reads1[] = { |
| 5936 | // No credentials. |
| 5937 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5938 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5939 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5940 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5941 | |
| 5942 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5943 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5944 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5945 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5946 | }; |
| 5947 | |
| 5948 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5949 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5950 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5951 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5952 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5954 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5958 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5960 | |
| 5961 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5963 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5964 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5965 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5966 | TestLoadTimingNotReused(load_timing_info, |
| 5967 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5969 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5970 | ASSERT_TRUE(response); |
| 5971 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5972 | EXPECT_EQ(407, response->headers->response_code()); |
| 5973 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5974 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5975 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5976 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5978 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5980 | |
| 5981 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5982 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5983 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5984 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5985 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5986 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5987 | TestLoadTimingReused(load_timing_info); |
| 5988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5989 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5990 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5991 | |
| 5992 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5993 | EXPECT_EQ(200, response->headers->response_code()); |
| 5994 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5995 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5996 | |
| 5997 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5998 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5999 | } |
| 6000 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6001 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6002 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6003 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6004 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6005 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6006 | request.traffic_annotation = |
| 6007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6008 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6009 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6010 | session_deps_.proxy_resolution_service = |
| 6011 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6013 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6014 | // Since we have proxy, should try to establish tunnel. |
| 6015 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6016 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6017 | "Host: www.example.org:443\r\n" |
| 6018 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6019 | }; |
| 6020 | |
| 6021 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6022 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6023 | // No response body because the test stops reading here. |
| 6024 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6025 | }; |
| 6026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6028 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6029 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6031 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6033 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6034 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6035 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6037 | |
| 6038 | rv = callback.WaitForResult(); |
| 6039 | EXPECT_EQ(expected_status, rv); |
| 6040 | } |
| 6041 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6042 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6043 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6044 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6045 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6046 | } |
| 6047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6048 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6049 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6050 | } |
| 6051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6052 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6053 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6054 | } |
| 6055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6056 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6057 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6058 | } |
| 6059 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6060 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6061 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6062 | } |
| 6063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6064 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6065 | ConnectStatusHelper( |
| 6066 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6067 | } |
| 6068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6069 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6070 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6071 | } |
| 6072 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6073 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6074 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6075 | } |
| 6076 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6077 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6078 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6079 | } |
| 6080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6081 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6082 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6083 | } |
| 6084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6085 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6086 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6087 | } |
| 6088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6089 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6090 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6091 | } |
| 6092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6093 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6094 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6095 | } |
| 6096 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6097 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6098 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6099 | } |
| 6100 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6101 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6102 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6103 | } |
| 6104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6105 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6106 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6107 | } |
| 6108 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6109 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6110 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6111 | } |
| 6112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6113 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6114 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6115 | } |
| 6116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6117 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6118 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6119 | } |
| 6120 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6121 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6122 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6123 | } |
| 6124 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6125 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6126 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6127 | } |
| 6128 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6129 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6130 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6131 | } |
| 6132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6133 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6134 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6135 | } |
| 6136 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6137 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6138 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6139 | } |
| 6140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6141 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6142 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6143 | } |
| 6144 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6145 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6146 | ConnectStatusHelperWithExpectedStatus( |
| 6147 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6148 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6149 | } |
| 6150 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6151 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6152 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6153 | } |
| 6154 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6155 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6156 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6157 | } |
| 6158 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6159 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6160 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6161 | } |
| 6162 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6163 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6164 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6165 | } |
| 6166 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6167 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6168 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6169 | } |
| 6170 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6171 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6172 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6173 | } |
| 6174 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6175 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6176 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6177 | } |
| 6178 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6179 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6180 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6181 | } |
| 6182 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6183 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6184 | ConnectStatusHelper( |
| 6185 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6186 | } |
| 6187 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6188 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6189 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6190 | } |
| 6191 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6192 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6193 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6194 | } |
| 6195 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6196 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6197 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6198 | } |
| 6199 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6200 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6201 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6202 | } |
| 6203 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6204 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6205 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6206 | } |
| 6207 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6208 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6209 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6210 | } |
| 6211 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6212 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6213 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6214 | } |
| 6215 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6216 | // Test the flow when both the proxy server AND origin server require |
| 6217 | // authentication. Again, this uses basic auth for both since that is |
| 6218 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6219 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6220 | HttpRequestInfo request; |
| 6221 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6222 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6223 | request.traffic_annotation = |
| 6224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6225 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6226 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6227 | session_deps_.proxy_resolution_service = |
| 6228 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6232 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6233 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6234 | MockWrite( |
| 6235 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6236 | "Host: www.example.org\r\n" |
| 6237 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6238 | }; |
| 6239 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6240 | MockRead data_reads1[] = { |
| 6241 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6242 | // Give a couple authenticate options (only the middle one is actually |
| 6243 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6244 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6245 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6246 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6247 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6248 | // Large content-length -- won't matter, as connection will be reset. |
| 6249 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6250 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6251 | }; |
| 6252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6253 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6254 | // request we should be issuing -- the final header line contains the |
| 6255 | // proxy's credentials. |
| 6256 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6257 | MockWrite( |
| 6258 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6259 | "Host: www.example.org\r\n" |
| 6260 | "Proxy-Connection: keep-alive\r\n" |
| 6261 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6262 | }; |
| 6263 | |
| 6264 | // Now the proxy server lets the request pass through to origin server. |
| 6265 | // The origin server responds with a 401. |
| 6266 | MockRead data_reads2[] = { |
| 6267 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6268 | // Note: We are using the same realm-name as the proxy server. This is |
| 6269 | // completely valid, as realms are unique across hosts. |
| 6270 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6271 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6272 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6273 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6274 | }; |
| 6275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6276 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6277 | // the credentials for both the proxy and origin server. |
| 6278 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6279 | MockWrite( |
| 6280 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6281 | "Host: www.example.org\r\n" |
| 6282 | "Proxy-Connection: keep-alive\r\n" |
| 6283 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6284 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6285 | }; |
| 6286 | |
| 6287 | // Lastly we get the desired content. |
| 6288 | MockRead data_reads3[] = { |
| 6289 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6290 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6291 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6292 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6293 | }; |
| 6294 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6295 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6296 | data_writes1, arraysize(data_writes1)); |
| 6297 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6298 | data_writes2, arraysize(data_writes2)); |
| 6299 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6300 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6301 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6302 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6303 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6305 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6306 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6307 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6309 | |
| 6310 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6314 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6315 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6316 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6317 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6318 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6319 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6320 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6321 | |
| 6322 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6323 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6325 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6326 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6327 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6329 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6331 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6332 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6334 | |
| 6335 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6338 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6339 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6340 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6341 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6342 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6343 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6344 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6345 | // authorization headers. |
| 6346 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6347 | // The NTLM authentication unit tests are based on known test data from the |
| 6348 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6349 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6350 | // for the implementation and testing of the protocol. |
| 6351 | // |
| 6352 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6353 | |
| 6354 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6355 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6356 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6357 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6358 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6359 | request.traffic_annotation = |
| 6360 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6361 | |
| 6362 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6363 | // to other auth schemes. |
| 6364 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6365 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6366 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6367 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6368 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6369 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6370 | // Generate the NTLM messages based on known test data. |
| 6371 | std::string negotiate_msg; |
| 6372 | std::string challenge_msg; |
| 6373 | std::string authenticate_msg; |
| 6374 | base::Base64Encode( |
| 6375 | base::StringPiece( |
| 6376 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6377 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6378 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6379 | base::Base64Encode( |
| 6380 | base::StringPiece( |
| 6381 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6382 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6383 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6384 | base::Base64Encode( |
| 6385 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6386 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6387 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6388 | arraysize( |
| 6389 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6390 | &authenticate_msg); |
| 6391 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6392 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6393 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6394 | "Host: server\r\n" |
| 6395 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6396 | }; |
| 6397 | |
| 6398 | MockRead data_reads1[] = { |
| 6399 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6400 | // Negotiate and NTLM are often requested together. However, we only want |
| 6401 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6402 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6403 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6404 | MockRead("Connection: close\r\n"), |
| 6405 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6406 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6407 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6408 | }; |
| 6409 | |
| 6410 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6411 | // After restarting with a null identity, this is the |
| 6412 | // request we should be issuing -- the final header line contains a Type |
| 6413 | // 1 message. |
| 6414 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6415 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6416 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6417 | "Authorization: NTLM "), |
| 6418 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6420 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6421 | // (using correct credentials). The second request continues on the |
| 6422 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6423 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6424 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6425 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6426 | "Authorization: NTLM "), |
| 6427 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6428 | }; |
| 6429 | |
| 6430 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6431 | // The origin server responds with a Type 2 message. |
| 6432 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6433 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6434 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6435 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6436 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6437 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6438 | // Lastly we get the desired content. |
| 6439 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6440 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6441 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6442 | }; |
| 6443 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6444 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6445 | data_writes1, arraysize(data_writes1)); |
| 6446 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6447 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6448 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6449 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6450 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6451 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6453 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6456 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6459 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6460 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6462 | |
| 6463 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6464 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6466 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6468 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6469 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6470 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6472 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6473 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6474 | rv = trans.RestartWithAuth( |
| 6475 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6476 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6478 | |
| 6479 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6482 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6483 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6484 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6485 | ASSERT_TRUE(response); |
| 6486 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6487 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6488 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6490 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6492 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6493 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6496 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6497 | ASSERT_TRUE(response); |
| 6498 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6499 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6500 | |
| 6501 | std::string response_data; |
| 6502 | rv = ReadTransaction(&trans, &response_data); |
| 6503 | EXPECT_THAT(rv, IsOk()); |
| 6504 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6505 | |
| 6506 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6507 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6508 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6509 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6510 | } |
| 6511 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6512 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6513 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6514 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6515 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6516 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6517 | request.traffic_annotation = |
| 6518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6519 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6520 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6521 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6523 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6524 | // Generate the NTLM messages based on known test data. |
| 6525 | std::string negotiate_msg; |
| 6526 | std::string challenge_msg; |
| 6527 | std::string authenticate_msg; |
| 6528 | base::Base64Encode( |
| 6529 | base::StringPiece( |
| 6530 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6531 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6532 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6533 | base::Base64Encode( |
| 6534 | base::StringPiece( |
| 6535 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6536 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6537 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6538 | base::Base64Encode( |
| 6539 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6540 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6541 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6542 | arraysize( |
| 6543 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6544 | &authenticate_msg); |
| 6545 | |
| 6546 | // The authenticate message when |kWrongPassword| is sent. |
| 6547 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6548 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6549 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6550 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6551 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6552 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6553 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6554 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6555 | // Sanity check that it's the same length as the correct authenticate message |
| 6556 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6557 | ASSERT_EQ(authenticate_msg.length(), |
| 6558 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6559 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6560 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6561 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6562 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6563 | "Host: server\r\n" |
| 6564 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6565 | }; |
| 6566 | |
| 6567 | MockRead data_reads1[] = { |
| 6568 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6569 | // Negotiate and NTLM are often requested together. However, we only want |
| 6570 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6571 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6572 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6573 | MockRead("Connection: close\r\n"), |
| 6574 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6575 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6576 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6577 | }; |
| 6578 | |
| 6579 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6580 | // After restarting with a null identity, this is the |
| 6581 | // request we should be issuing -- the final header line contains a Type |
| 6582 | // 1 message. |
| 6583 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6584 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6585 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6586 | "Authorization: NTLM "), |
| 6587 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6589 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6590 | // (using incorrect credentials). The second request continues on the |
| 6591 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6592 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6593 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6594 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6595 | "Authorization: NTLM "), |
| 6596 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6597 | }; |
| 6598 | |
| 6599 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6600 | // The origin server responds with a Type 2 message. |
| 6601 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6602 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6603 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6604 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6605 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6606 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6607 | // Wrong password. |
| 6608 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6609 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6610 | MockRead("Content-Length: 42\r\n"), |
| 6611 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6612 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6613 | }; |
| 6614 | |
| 6615 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6616 | // After restarting with a null identity, this is the |
| 6617 | // request we should be issuing -- the final header line contains a Type |
| 6618 | // 1 message. |
| 6619 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6620 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6621 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6622 | "Authorization: NTLM "), |
| 6623 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6625 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6626 | // (the credentials for the origin server). The second request continues |
| 6627 | // on the same connection. |
| 6628 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6629 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6630 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6631 | "Authorization: NTLM "), |
| 6632 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6633 | }; |
| 6634 | |
| 6635 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6636 | // The origin server responds with a Type 2 message. |
| 6637 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6638 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6639 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6640 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6641 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6642 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6643 | // Lastly we get the desired content. |
| 6644 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6645 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6646 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6647 | }; |
| 6648 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6649 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6650 | data_writes1, arraysize(data_writes1)); |
| 6651 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6652 | data_writes2, arraysize(data_writes2)); |
| 6653 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6654 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6655 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6656 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6657 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6658 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6659 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6661 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6662 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6663 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6664 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6665 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6666 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6668 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6670 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6672 | |
| 6673 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6674 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6676 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6678 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6679 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6680 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6681 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6682 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6683 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6684 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6685 | rv = trans.RestartWithAuth( |
| 6686 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6687 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6688 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6689 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6690 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6691 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6693 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6694 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6695 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6697 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6698 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6699 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6701 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6702 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6703 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6704 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6705 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6706 | |
| 6707 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6708 | rv = trans.RestartWithAuth( |
| 6709 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6710 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6712 | |
| 6713 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6716 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6718 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6719 | |
| 6720 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6721 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6722 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6723 | |
| 6724 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6725 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6727 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6728 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6729 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6730 | |
| 6731 | std::string response_data; |
| 6732 | rv = ReadTransaction(&trans, &response_data); |
| 6733 | EXPECT_THAT(rv, IsOk()); |
| 6734 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6735 | |
| 6736 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6737 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6738 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6739 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6740 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6741 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6742 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6743 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6744 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6745 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6746 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6747 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6748 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6749 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6750 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6751 | |
| 6752 | HttpRequestInfo request; |
| 6753 | request.method = "GET"; |
| 6754 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6755 | request.traffic_annotation = |
| 6756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6757 | |
| 6758 | // First request without credentials. |
| 6759 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6760 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6761 | 1, std::move(request_headers0), LOWEST, true)); |
| 6762 | |
| 6763 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6764 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6765 | response_headers0["www-authenticate"] = "NTLM"; |
| 6766 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6767 | 1, std::move(response_headers0), true)); |
| 6768 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6769 | // Stream 1 is closed. |
| 6770 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6771 | |
| 6772 | // Generate the NTLM messages based on known test data. |
| 6773 | std::string negotiate_msg; |
| 6774 | std::string challenge_msg; |
| 6775 | std::string authenticate_msg; |
| 6776 | base::Base64Encode( |
| 6777 | base::StringPiece( |
| 6778 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6779 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6780 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6781 | base::Base64Encode( |
| 6782 | base::StringPiece( |
| 6783 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6784 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6785 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6786 | base::Base64Encode( |
| 6787 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6788 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6789 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6790 | arraysize( |
| 6791 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6792 | &authenticate_msg); |
| 6793 | |
| 6794 | // Retry with authorization header. |
| 6795 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6796 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6797 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6798 | 3, std::move(request_headers1), LOWEST, true)); |
| 6799 | |
| 6800 | SpdySerializedFrame rst( |
| 6801 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6802 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6803 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6804 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6805 | |
| 6806 | // Retry yet again using HTTP/1.1. |
| 6807 | MockWrite writes1[] = { |
| 6808 | // After restarting with a null identity, this is the |
| 6809 | // request we should be issuing -- the final header line contains a Type |
| 6810 | // 1 message. |
| 6811 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6812 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6813 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6814 | "Authorization: NTLM "), |
| 6815 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6816 | |
| 6817 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6818 | // (the credentials for the origin server). The second request continues |
| 6819 | // on the same connection. |
| 6820 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6821 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6822 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6823 | "Authorization: NTLM "), |
| 6824 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6825 | }; |
| 6826 | |
| 6827 | MockRead reads1[] = { |
| 6828 | // The origin server responds with a Type 2 message. |
| 6829 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6830 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6831 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6832 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6833 | MockRead("You are not authorized to view this page\r\n"), |
| 6834 | |
| 6835 | // Lastly we get the desired content. |
| 6836 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6837 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6838 | 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] | 6839 | }; |
| 6840 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6841 | arraysize(writes0)); |
| 6842 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6843 | arraysize(writes1)); |
| 6844 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6845 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6846 | |
| 6847 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6848 | ssl0.next_proto = kProtoHTTP2; |
| 6849 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6850 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6851 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6852 | |
| 6853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6855 | |
| 6856 | TestCompletionCallback callback1; |
| 6857 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6859 | |
| 6860 | rv = callback1.WaitForResult(); |
| 6861 | EXPECT_THAT(rv, IsOk()); |
| 6862 | |
| 6863 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6864 | |
| 6865 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6866 | ASSERT_TRUE(response); |
| 6867 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6868 | |
| 6869 | TestCompletionCallback callback2; |
| 6870 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6871 | rv = trans.RestartWithAuth( |
| 6872 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6873 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6875 | |
| 6876 | rv = callback2.WaitForResult(); |
| 6877 | EXPECT_THAT(rv, IsOk()); |
| 6878 | |
| 6879 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6880 | |
| 6881 | response = trans.GetResponseInfo(); |
| 6882 | ASSERT_TRUE(response); |
| 6883 | EXPECT_FALSE(response->auth_challenge); |
| 6884 | |
| 6885 | TestCompletionCallback callback3; |
| 6886 | |
| 6887 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6889 | |
| 6890 | rv = callback3.WaitForResult(); |
| 6891 | EXPECT_THAT(rv, IsOk()); |
| 6892 | |
| 6893 | response = trans.GetResponseInfo(); |
| 6894 | ASSERT_TRUE(response); |
| 6895 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6896 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6897 | |
| 6898 | std::string response_data; |
| 6899 | rv = ReadTransaction(&trans, &response_data); |
| 6900 | EXPECT_THAT(rv, IsOk()); |
| 6901 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6902 | |
| 6903 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6904 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6905 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6906 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6907 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6908 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6909 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6910 | // Test reading a server response which has only headers, and no body. |
| 6911 | // After some maximum number of bytes is consumed, the transaction should |
| 6912 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6913 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6914 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6915 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6916 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6917 | request.traffic_annotation = |
| 6918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6922 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6923 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6924 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6925 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6926 | |
| 6927 | MockRead data_reads[] = { |
| 6928 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6929 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6930 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6932 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6933 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6936 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6937 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6938 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6940 | |
| 6941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6942 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6943 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6944 | |
| 6945 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6946 | // establish tunnel. |
| 6947 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6948 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6949 | HttpRequestInfo request; |
| 6950 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6951 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6952 | request.traffic_annotation = |
| 6953 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6954 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6955 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6956 | session_deps_.proxy_resolution_service = |
| 6957 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6958 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6960 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6961 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6962 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6963 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6964 | // Since we have proxy, should try to establish tunnel. |
| 6965 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6966 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6967 | "Host: www.example.org:443\r\n" |
| 6968 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6969 | }; |
| 6970 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6971 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6972 | // connection. Usually a proxy would return 501 (not implemented), |
| 6973 | // or 200 (tunnel established). |
| 6974 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6975 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6976 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6977 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6978 | }; |
| 6979 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6980 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6981 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6982 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6983 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6984 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6985 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6986 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6988 | |
| 6989 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6990 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6991 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6992 | // Empty the current queue. This is necessary because idle sockets are |
| 6993 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6994 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6995 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6996 | // We now check to make sure the TCPClientSocket was not added back to |
| 6997 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6998 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6999 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7000 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7001 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7002 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7003 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7004 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7005 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7006 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7007 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7009 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7010 | request.traffic_annotation = |
| 7011 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7012 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7016 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7017 | MockRead data_reads[] = { |
| 7018 | // A part of the response body is received with the response headers. |
| 7019 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7020 | // The rest of the response body is received in two parts. |
| 7021 | MockRead("lo"), |
| 7022 | MockRead(" world"), |
| 7023 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7025 | }; |
| 7026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7030 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7034 | |
| 7035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7038 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7039 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7040 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7041 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7042 | std::string status_line = response->headers->GetStatusLine(); |
| 7043 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7044 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7045 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7046 | |
| 7047 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7048 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7049 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7050 | EXPECT_EQ("hello world", response_data); |
| 7051 | |
| 7052 | // Empty the current queue. This is necessary because idle sockets are |
| 7053 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7054 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7055 | |
| 7056 | // 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] | 7057 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7058 | } |
| 7059 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7060 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7061 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7062 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7063 | HttpRequestInfo request; |
| 7064 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7065 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7066 | request.traffic_annotation = |
| 7067 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7068 | |
| 7069 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7070 | MockWrite( |
| 7071 | "GET / HTTP/1.1\r\n" |
| 7072 | "Host: www.example.org\r\n" |
| 7073 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7074 | }; |
| 7075 | |
| 7076 | MockRead data_reads[] = { |
| 7077 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7078 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7079 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7080 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7081 | }; |
| 7082 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7083 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7084 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7085 | |
| 7086 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7087 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7088 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7090 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7093 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7094 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7095 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7096 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7098 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7100 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7101 | ASSERT_TRUE(response); |
| 7102 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7103 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7104 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7105 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7106 | |
| 7107 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7108 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7109 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7110 | EXPECT_EQ("hello world", response_data); |
| 7111 | |
| 7112 | // Empty the current queue. This is necessary because idle sockets are |
| 7113 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7114 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7115 | |
| 7116 | // 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] | 7117 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7118 | } |
| 7119 | |
| 7120 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7121 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7122 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7123 | HttpRequestInfo request; |
| 7124 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7125 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7126 | request.traffic_annotation = |
| 7127 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7128 | |
| 7129 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7130 | MockWrite( |
| 7131 | "GET / HTTP/1.1\r\n" |
| 7132 | "Host: www.example.org\r\n" |
| 7133 | "Connection: keep-alive\r\n\r\n"), |
| 7134 | MockWrite( |
| 7135 | "GET / HTTP/1.1\r\n" |
| 7136 | "Host: www.example.org\r\n" |
| 7137 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7138 | }; |
| 7139 | |
| 7140 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7141 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7142 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7143 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7144 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7145 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7148 | |
| 7149 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7150 | data_writes, arraysize(data_writes)); |
| 7151 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 7152 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7154 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7155 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7156 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7159 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7161 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7162 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7163 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7164 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7165 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7166 | |
| 7167 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7168 | ASSERT_TRUE(response); |
| 7169 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7170 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7171 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7172 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7173 | |
| 7174 | std::string response_data; |
| 7175 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7177 | EXPECT_EQ("hello world", response_data); |
| 7178 | |
| 7179 | // Empty the current queue. This is necessary because idle sockets are |
| 7180 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7181 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7182 | |
| 7183 | // 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] | 7184 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7185 | |
| 7186 | // Now start the second transaction, which should reuse the previous socket. |
| 7187 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7188 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7189 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7190 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7191 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7192 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7194 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7195 | |
| 7196 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7197 | ASSERT_TRUE(response); |
| 7198 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7199 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7200 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7201 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7202 | |
| 7203 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7204 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7205 | EXPECT_EQ("hello world", response_data); |
| 7206 | |
| 7207 | // Empty the current queue. This is necessary because idle sockets are |
| 7208 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7209 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7210 | |
| 7211 | // 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] | 7212 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7213 | } |
| 7214 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7215 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7216 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7217 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7218 | HttpRequestInfo request; |
| 7219 | request.method = "GET"; |
| 7220 | request.url = GURL("http://www.example.org/"); |
| 7221 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7222 | request.traffic_annotation = |
| 7223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7224 | |
| 7225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7228 | |
| 7229 | MockRead data_reads[] = { |
| 7230 | // A part of the response body is received with the response headers. |
| 7231 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7232 | // The rest of the response body is received in two parts. |
| 7233 | MockRead("lo"), MockRead(" world"), |
| 7234 | MockRead("junk"), // Should not be read!! |
| 7235 | MockRead(SYNCHRONOUS, OK), |
| 7236 | }; |
| 7237 | |
| 7238 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7240 | |
| 7241 | TestCompletionCallback callback; |
| 7242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7245 | |
| 7246 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7248 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7249 | ASSERT_TRUE(response); |
| 7250 | EXPECT_TRUE(response->headers); |
| 7251 | std::string status_line = response->headers->GetStatusLine(); |
| 7252 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7253 | |
| 7254 | // Make memory critical notification and ensure the transaction still has been |
| 7255 | // operating right. |
| 7256 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7257 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7258 | base::RunLoop().RunUntilIdle(); |
| 7259 | |
| 7260 | // Socket should not be flushed as long as it is not idle. |
| 7261 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7262 | |
| 7263 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7264 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7265 | EXPECT_THAT(rv, IsOk()); |
| 7266 | EXPECT_EQ("hello world", response_data); |
| 7267 | |
| 7268 | // Empty the current queue. This is necessary because idle sockets are |
| 7269 | // added to the connection pool asynchronously with a PostTask. |
| 7270 | base::RunLoop().RunUntilIdle(); |
| 7271 | |
| 7272 | // We now check to make sure the socket was added back to the pool. |
| 7273 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7274 | |
| 7275 | // Idle sockets should be flushed now. |
| 7276 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7277 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7278 | base::RunLoop().RunUntilIdle(); |
| 7279 | |
| 7280 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7281 | } |
| 7282 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7283 | // Disable idle socket closing on memory pressure. |
| 7284 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7285 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7286 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7287 | HttpRequestInfo request; |
| 7288 | request.method = "GET"; |
| 7289 | request.url = GURL("http://www.example.org/"); |
| 7290 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7291 | request.traffic_annotation = |
| 7292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7293 | |
| 7294 | // Disable idle socket closing on memory pressure. |
| 7295 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7296 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7297 | |
| 7298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7299 | |
| 7300 | MockRead data_reads[] = { |
| 7301 | // A part of the response body is received with the response headers. |
| 7302 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7303 | // The rest of the response body is received in two parts. |
| 7304 | MockRead("lo"), MockRead(" world"), |
| 7305 | MockRead("junk"), // Should not be read!! |
| 7306 | MockRead(SYNCHRONOUS, OK), |
| 7307 | }; |
| 7308 | |
| 7309 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7310 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7311 | |
| 7312 | TestCompletionCallback callback; |
| 7313 | |
| 7314 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7316 | |
| 7317 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7318 | |
| 7319 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7320 | ASSERT_TRUE(response); |
| 7321 | EXPECT_TRUE(response->headers); |
| 7322 | std::string status_line = response->headers->GetStatusLine(); |
| 7323 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7324 | |
| 7325 | // Make memory critical notification and ensure the transaction still has been |
| 7326 | // operating right. |
| 7327 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7328 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7329 | base::RunLoop().RunUntilIdle(); |
| 7330 | |
| 7331 | // Socket should not be flushed as long as it is not idle. |
| 7332 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7333 | |
| 7334 | std::string response_data; |
| 7335 | rv = ReadTransaction(&trans, &response_data); |
| 7336 | EXPECT_THAT(rv, IsOk()); |
| 7337 | EXPECT_EQ("hello world", response_data); |
| 7338 | |
| 7339 | // Empty the current queue. This is necessary because idle sockets are |
| 7340 | // added to the connection pool asynchronously with a PostTask. |
| 7341 | base::RunLoop().RunUntilIdle(); |
| 7342 | |
| 7343 | // We now check to make sure the socket was added back to the pool. |
| 7344 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7345 | |
| 7346 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7347 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7348 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7349 | base::RunLoop().RunUntilIdle(); |
| 7350 | |
| 7351 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7352 | |
| 7353 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7354 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7355 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7356 | base::RunLoop().RunUntilIdle(); |
| 7357 | |
| 7358 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7359 | } |
| 7360 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7361 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7362 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7363 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7364 | HttpRequestInfo request; |
| 7365 | request.method = "GET"; |
| 7366 | request.url = GURL("https://www.example.org/"); |
| 7367 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7368 | request.traffic_annotation = |
| 7369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7370 | |
| 7371 | MockWrite data_writes[] = { |
| 7372 | MockWrite("GET / HTTP/1.1\r\n" |
| 7373 | "Host: www.example.org\r\n" |
| 7374 | "Connection: keep-alive\r\n\r\n"), |
| 7375 | }; |
| 7376 | |
| 7377 | MockRead data_reads[] = { |
| 7378 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7379 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7380 | |
| 7381 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7383 | |
| 7384 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7385 | arraysize(data_writes)); |
| 7386 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7387 | |
| 7388 | TestCompletionCallback callback; |
| 7389 | |
| 7390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7392 | |
| 7393 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7394 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7395 | |
| 7396 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7399 | ASSERT_TRUE(response); |
| 7400 | ASSERT_TRUE(response->headers); |
| 7401 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7402 | |
| 7403 | // Make memory critical notification and ensure the transaction still has been |
| 7404 | // operating right. |
| 7405 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7406 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7407 | base::RunLoop().RunUntilIdle(); |
| 7408 | |
| 7409 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7410 | |
| 7411 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7412 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7413 | EXPECT_THAT(rv, IsOk()); |
| 7414 | EXPECT_EQ("hello world", response_data); |
| 7415 | |
| 7416 | // Empty the current queue. This is necessary because idle sockets are |
| 7417 | // added to the connection pool asynchronously with a PostTask. |
| 7418 | base::RunLoop().RunUntilIdle(); |
| 7419 | |
| 7420 | // We now check to make sure the socket was added back to the pool. |
| 7421 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7422 | |
| 7423 | // Make memory notification once again and ensure idle socket is closed. |
| 7424 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7425 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7426 | base::RunLoop().RunUntilIdle(); |
| 7427 | |
| 7428 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7429 | } |
| 7430 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7431 | // Make sure that we recycle a socket after a zero-length response. |
| 7432 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7433 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7434 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7435 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7436 | request.url = GURL( |
| 7437 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7438 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7439 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7440 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7441 | request.traffic_annotation = |
| 7442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7443 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7444 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7445 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7446 | MockRead data_reads[] = { |
| 7447 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7448 | "Content-Length: 0\r\n" |
| 7449 | "Content-Type: text/html\r\n\r\n"), |
| 7450 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7451 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7452 | }; |
| 7453 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7454 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7455 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7456 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7457 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7458 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7459 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7461 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7463 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7465 | |
| 7466 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7469 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7470 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7471 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7472 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7473 | std::string status_line = response->headers->GetStatusLine(); |
| 7474 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7475 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7476 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7477 | |
| 7478 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7479 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7481 | EXPECT_EQ("", response_data); |
| 7482 | |
| 7483 | // Empty the current queue. This is necessary because idle sockets are |
| 7484 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7485 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7486 | |
| 7487 | // 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] | 7488 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7489 | } |
| 7490 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7491 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7492 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7493 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7494 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7495 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7496 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7497 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7498 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7499 | // after use. |
| 7500 | request[0].method = "GET"; |
| 7501 | request[0].url = GURL("http://www.google.com/"); |
| 7502 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7503 | request[0].traffic_annotation = |
| 7504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7505 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7506 | // transaction 1. The first attempts fails when writing the POST data. |
| 7507 | // This causes the transaction to retry with a new socket. The second |
| 7508 | // attempt succeeds. |
| 7509 | request[1].method = "POST"; |
| 7510 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7511 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7512 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7513 | request[1].traffic_annotation = |
| 7514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7517 | |
| 7518 | // The first socket is used for transaction 1 and the first attempt of |
| 7519 | // transaction 2. |
| 7520 | |
| 7521 | // The response of transaction 1. |
| 7522 | MockRead data_reads1[] = { |
| 7523 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7524 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7526 | }; |
| 7527 | // The mock write results of transaction 1 and the first attempt of |
| 7528 | // transaction 2. |
| 7529 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7530 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7531 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7532 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7533 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7534 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7535 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7536 | |
| 7537 | // The second socket is used for the second attempt of transaction 2. |
| 7538 | |
| 7539 | // The response of transaction 2. |
| 7540 | MockRead data_reads2[] = { |
| 7541 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7542 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7543 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7544 | }; |
| 7545 | // The mock write results of the second attempt of transaction 2. |
| 7546 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7547 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7548 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7549 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7550 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7551 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7552 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7553 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7555 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7556 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7557 | "hello world", "welcome" |
| 7558 | }; |
| 7559 | |
| 7560 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7563 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7565 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7567 | |
| 7568 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7569 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7572 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7573 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7574 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7575 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7576 | |
| 7577 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7578 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7579 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7580 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7581 | } |
| 7582 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7583 | |
| 7584 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7585 | // 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] | 7586 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7587 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7588 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7590 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7591 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7592 | request.traffic_annotation = |
| 7593 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7594 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7597 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7598 | // The password contains an escaped character -- for this test to pass it |
| 7599 | // will need to be unescaped by HttpNetworkTransaction. |
| 7600 | EXPECT_EQ("b%40r", request.url.password()); |
| 7601 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7602 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7603 | MockWrite( |
| 7604 | "GET / HTTP/1.1\r\n" |
| 7605 | "Host: www.example.org\r\n" |
| 7606 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7607 | }; |
| 7608 | |
| 7609 | MockRead data_reads1[] = { |
| 7610 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7611 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7612 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7613 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7614 | }; |
| 7615 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7616 | // After the challenge above, the transaction will be restarted using the |
| 7617 | // identity from the url (foo, b@r) to answer the challenge. |
| 7618 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7619 | MockWrite( |
| 7620 | "GET / HTTP/1.1\r\n" |
| 7621 | "Host: www.example.org\r\n" |
| 7622 | "Connection: keep-alive\r\n" |
| 7623 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7624 | }; |
| 7625 | |
| 7626 | MockRead data_reads2[] = { |
| 7627 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7628 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7629 | MockRead(SYNCHRONOUS, OK), |
| 7630 | }; |
| 7631 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7632 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7633 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7634 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7635 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7636 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7637 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7638 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7639 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7640 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7642 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7643 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7644 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7645 | |
| 7646 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7647 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7648 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7649 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7650 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7651 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7653 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7654 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7655 | |
| 7656 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7657 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7658 | |
| 7659 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7660 | |
| 7661 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7662 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7663 | } |
| 7664 | |
| 7665 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7666 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7667 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7668 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7669 | HttpRequestInfo request; |
| 7670 | request.method = "GET"; |
| 7671 | // Note: the URL has a username:password in it. The password "baz" is |
| 7672 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7673 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7674 | |
| 7675 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7676 | request.traffic_annotation = |
| 7677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7681 | |
| 7682 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7683 | MockWrite( |
| 7684 | "GET / HTTP/1.1\r\n" |
| 7685 | "Host: www.example.org\r\n" |
| 7686 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7687 | }; |
| 7688 | |
| 7689 | MockRead data_reads1[] = { |
| 7690 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7691 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7692 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7693 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7694 | }; |
| 7695 | |
| 7696 | // After the challenge above, the transaction will be restarted using the |
| 7697 | // identity from the url (foo, baz) to answer the challenge. |
| 7698 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7699 | MockWrite( |
| 7700 | "GET / HTTP/1.1\r\n" |
| 7701 | "Host: www.example.org\r\n" |
| 7702 | "Connection: keep-alive\r\n" |
| 7703 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7704 | }; |
| 7705 | |
| 7706 | MockRead data_reads2[] = { |
| 7707 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7708 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7709 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7710 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7711 | }; |
| 7712 | |
| 7713 | // After the challenge above, the transaction will be restarted using the |
| 7714 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7715 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7716 | MockWrite( |
| 7717 | "GET / HTTP/1.1\r\n" |
| 7718 | "Host: www.example.org\r\n" |
| 7719 | "Connection: keep-alive\r\n" |
| 7720 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7721 | }; |
| 7722 | |
| 7723 | MockRead data_reads3[] = { |
| 7724 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7725 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7726 | MockRead(SYNCHRONOUS, OK), |
| 7727 | }; |
| 7728 | |
| 7729 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7730 | data_writes1, arraysize(data_writes1)); |
| 7731 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7732 | data_writes2, arraysize(data_writes2)); |
| 7733 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7734 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7735 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7736 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7737 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7738 | |
| 7739 | TestCompletionCallback callback1; |
| 7740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7741 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7743 | |
| 7744 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7745 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7747 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7748 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7749 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7751 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7752 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7753 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7755 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7756 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7757 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7758 | |
| 7759 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7760 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7762 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7763 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7764 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7766 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7767 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7768 | |
| 7769 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7770 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7771 | |
| 7772 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7773 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7774 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7775 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7776 | } |
| 7777 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7778 | |
| 7779 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7780 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7781 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7782 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7783 | HttpRequestInfo request; |
| 7784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7785 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7786 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7787 | request.traffic_annotation = |
| 7788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7792 | |
| 7793 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7794 | MockWrite( |
| 7795 | "GET / HTTP/1.1\r\n" |
| 7796 | "Host: www.example.org\r\n" |
| 7797 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7798 | }; |
| 7799 | |
| 7800 | MockRead data_reads1[] = { |
| 7801 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7802 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7803 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7804 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7805 | }; |
| 7806 | |
| 7807 | // After the challenge above, the transaction will be restarted using the |
| 7808 | // identity supplied by the user, not the one in the URL, to answer the |
| 7809 | // challenge. |
| 7810 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7811 | MockWrite( |
| 7812 | "GET / HTTP/1.1\r\n" |
| 7813 | "Host: www.example.org\r\n" |
| 7814 | "Connection: keep-alive\r\n" |
| 7815 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7816 | }; |
| 7817 | |
| 7818 | MockRead data_reads3[] = { |
| 7819 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7820 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7821 | MockRead(SYNCHRONOUS, OK), |
| 7822 | }; |
| 7823 | |
| 7824 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7825 | data_writes1, arraysize(data_writes1)); |
| 7826 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7827 | data_writes3, arraysize(data_writes3)); |
| 7828 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7829 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7830 | |
| 7831 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7832 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7834 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7835 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7836 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7838 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7839 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7840 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7841 | |
| 7842 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7843 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7845 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7846 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7847 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7849 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7850 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7851 | |
| 7852 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7853 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7854 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7855 | |
| 7856 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7857 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7858 | } |
| 7859 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7860 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7861 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7863 | |
| 7864 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7865 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7866 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7867 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7868 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7869 | request.traffic_annotation = |
| 7870 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7873 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7874 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7875 | MockWrite( |
| 7876 | "GET /x/y/z HTTP/1.1\r\n" |
| 7877 | "Host: www.example.org\r\n" |
| 7878 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7879 | }; |
| 7880 | |
| 7881 | MockRead data_reads1[] = { |
| 7882 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7883 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7884 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7885 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7886 | }; |
| 7887 | |
| 7888 | // Resend with authorization (username=foo, password=bar) |
| 7889 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7890 | MockWrite( |
| 7891 | "GET /x/y/z HTTP/1.1\r\n" |
| 7892 | "Host: www.example.org\r\n" |
| 7893 | "Connection: keep-alive\r\n" |
| 7894 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7895 | }; |
| 7896 | |
| 7897 | // Sever accepts the authorization. |
| 7898 | MockRead data_reads2[] = { |
| 7899 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7900 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7901 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7902 | }; |
| 7903 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7904 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7905 | data_writes1, arraysize(data_writes1)); |
| 7906 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7907 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7908 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7909 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7911 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7912 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7913 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7915 | |
| 7916 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7919 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7920 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7921 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7923 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7925 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7926 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7927 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7928 | |
| 7929 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7930 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7932 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7933 | ASSERT_TRUE(response); |
| 7934 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7935 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7936 | } |
| 7937 | |
| 7938 | // ------------------------------------------------------------------------ |
| 7939 | |
| 7940 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7941 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7942 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7943 | request.method = "GET"; |
| 7944 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7945 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7946 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7947 | request.traffic_annotation = |
| 7948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7951 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7952 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7953 | MockWrite( |
| 7954 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7955 | "Host: www.example.org\r\n" |
| 7956 | "Connection: keep-alive\r\n" |
| 7957 | // Send preemptive authorization for MyRealm1 |
| 7958 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7959 | }; |
| 7960 | |
| 7961 | // The server didn't like the preemptive authorization, and |
| 7962 | // challenges us for a different realm (MyRealm2). |
| 7963 | MockRead data_reads1[] = { |
| 7964 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7965 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7966 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7967 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7968 | }; |
| 7969 | |
| 7970 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7971 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7972 | MockWrite( |
| 7973 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7974 | "Host: www.example.org\r\n" |
| 7975 | "Connection: keep-alive\r\n" |
| 7976 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7977 | }; |
| 7978 | |
| 7979 | // Sever accepts the authorization. |
| 7980 | MockRead data_reads2[] = { |
| 7981 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7982 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7983 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7984 | }; |
| 7985 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7987 | data_writes1, arraysize(data_writes1)); |
| 7988 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7989 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7990 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7991 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7993 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7995 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7997 | |
| 7998 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7999 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8001 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8002 | ASSERT_TRUE(response); |
| 8003 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8004 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8005 | EXPECT_EQ("http://www.example.org", |
| 8006 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8007 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8008 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8010 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8012 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8013 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8015 | |
| 8016 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8017 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8019 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8020 | ASSERT_TRUE(response); |
| 8021 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8022 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8023 | } |
| 8024 | |
| 8025 | // ------------------------------------------------------------------------ |
| 8026 | |
| 8027 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8028 | // succeed with preemptive authorization. |
| 8029 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8030 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8032 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8033 | request.traffic_annotation = |
| 8034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8037 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8038 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8039 | MockWrite( |
| 8040 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8041 | "Host: www.example.org\r\n" |
| 8042 | "Connection: keep-alive\r\n" |
| 8043 | // The authorization for MyRealm1 gets sent preemptively |
| 8044 | // (since the url is in the same protection space) |
| 8045 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8046 | }; |
| 8047 | |
| 8048 | // Sever accepts the preemptive authorization |
| 8049 | MockRead data_reads1[] = { |
| 8050 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8051 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8052 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8053 | }; |
| 8054 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8055 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8056 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8057 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8059 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8061 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8063 | |
| 8064 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8068 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8069 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8070 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8071 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8072 | } |
| 8073 | |
| 8074 | // ------------------------------------------------------------------------ |
| 8075 | |
| 8076 | // Transaction 4: request another URL in MyRealm (however the |
| 8077 | // url is not known to belong to the protection space, so no pre-auth). |
| 8078 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8079 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8081 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8082 | request.traffic_annotation = |
| 8083 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8086 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8087 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8088 | MockWrite( |
| 8089 | "GET /x/1 HTTP/1.1\r\n" |
| 8090 | "Host: www.example.org\r\n" |
| 8091 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8092 | }; |
| 8093 | |
| 8094 | MockRead data_reads1[] = { |
| 8095 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8096 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8097 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8098 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8099 | }; |
| 8100 | |
| 8101 | // Resend with authorization from MyRealm's cache. |
| 8102 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8103 | MockWrite( |
| 8104 | "GET /x/1 HTTP/1.1\r\n" |
| 8105 | "Host: www.example.org\r\n" |
| 8106 | "Connection: keep-alive\r\n" |
| 8107 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8108 | }; |
| 8109 | |
| 8110 | // Sever accepts the authorization. |
| 8111 | MockRead data_reads2[] = { |
| 8112 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8113 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8114 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8115 | }; |
| 8116 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8117 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8118 | data_writes1, arraysize(data_writes1)); |
| 8119 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8120 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8121 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8122 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8123 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8124 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8125 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8126 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8128 | |
| 8129 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8130 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8132 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8133 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8134 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8135 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8136 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8137 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8138 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8140 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8141 | ASSERT_TRUE(response); |
| 8142 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8143 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8144 | } |
| 8145 | |
| 8146 | // ------------------------------------------------------------------------ |
| 8147 | |
| 8148 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8149 | // cached identity. Should invalidate and re-prompt. |
| 8150 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8151 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8153 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8154 | request.traffic_annotation = |
| 8155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8158 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8159 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8160 | MockWrite( |
| 8161 | "GET /p/q/t HTTP/1.1\r\n" |
| 8162 | "Host: www.example.org\r\n" |
| 8163 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8164 | }; |
| 8165 | |
| 8166 | MockRead data_reads1[] = { |
| 8167 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8168 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8169 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8170 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8171 | }; |
| 8172 | |
| 8173 | // Resend with authorization from cache for MyRealm. |
| 8174 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8175 | MockWrite( |
| 8176 | "GET /p/q/t HTTP/1.1\r\n" |
| 8177 | "Host: www.example.org\r\n" |
| 8178 | "Connection: keep-alive\r\n" |
| 8179 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8180 | }; |
| 8181 | |
| 8182 | // Sever rejects the authorization. |
| 8183 | MockRead data_reads2[] = { |
| 8184 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8185 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8186 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8187 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8188 | }; |
| 8189 | |
| 8190 | // At this point we should prompt for new credentials for MyRealm. |
| 8191 | // Restart with username=foo3, password=foo4. |
| 8192 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8193 | MockWrite( |
| 8194 | "GET /p/q/t HTTP/1.1\r\n" |
| 8195 | "Host: www.example.org\r\n" |
| 8196 | "Connection: keep-alive\r\n" |
| 8197 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8198 | }; |
| 8199 | |
| 8200 | // Sever accepts the authorization. |
| 8201 | MockRead data_reads3[] = { |
| 8202 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8203 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8205 | }; |
| 8206 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8207 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8208 | data_writes1, arraysize(data_writes1)); |
| 8209 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8210 | data_writes2, arraysize(data_writes2)); |
| 8211 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8212 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8213 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8214 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8215 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8217 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8218 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8219 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8221 | |
| 8222 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8223 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8225 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8226 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8227 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8229 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8230 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8231 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8233 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8234 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8235 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8236 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8237 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8239 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8240 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8242 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8243 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8246 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8247 | ASSERT_TRUE(response); |
| 8248 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8249 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8250 | } |
| 8251 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8252 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8253 | // Tests that nonce count increments when multiple auth attempts |
| 8254 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8255 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8256 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8257 | new HttpAuthHandlerDigest::Factory(); |
| 8258 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8259 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8260 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8261 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8263 | |
| 8264 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8265 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8266 | HttpRequestInfo request; |
| 8267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8268 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8269 | request.traffic_annotation = |
| 8270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8273 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8274 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8275 | MockWrite( |
| 8276 | "GET /x/y/z HTTP/1.1\r\n" |
| 8277 | "Host: www.example.org\r\n" |
| 8278 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8279 | }; |
| 8280 | |
| 8281 | MockRead data_reads1[] = { |
| 8282 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8283 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8284 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8286 | }; |
| 8287 | |
| 8288 | // Resend with authorization (username=foo, password=bar) |
| 8289 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8290 | MockWrite( |
| 8291 | "GET /x/y/z HTTP/1.1\r\n" |
| 8292 | "Host: www.example.org\r\n" |
| 8293 | "Connection: keep-alive\r\n" |
| 8294 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8295 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8296 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8297 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8298 | }; |
| 8299 | |
| 8300 | // Sever accepts the authorization. |
| 8301 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8302 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8303 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8304 | }; |
| 8305 | |
| 8306 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8307 | data_writes1, arraysize(data_writes1)); |
| 8308 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8309 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8310 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8311 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8313 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8315 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8317 | |
| 8318 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8319 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8321 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8322 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8323 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8324 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8325 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8327 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8328 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8330 | |
| 8331 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8334 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8335 | ASSERT_TRUE(response); |
| 8336 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8337 | } |
| 8338 | |
| 8339 | // ------------------------------------------------------------------------ |
| 8340 | |
| 8341 | // Transaction 2: Request another resource in digestive's protection space. |
| 8342 | // This will preemptively add an Authorization header which should have an |
| 8343 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8344 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8345 | HttpRequestInfo request; |
| 8346 | request.method = "GET"; |
| 8347 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8348 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8349 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8350 | request.traffic_annotation = |
| 8351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8354 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8355 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8356 | MockWrite( |
| 8357 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8358 | "Host: www.example.org\r\n" |
| 8359 | "Connection: keep-alive\r\n" |
| 8360 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8361 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8362 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8363 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8364 | }; |
| 8365 | |
| 8366 | // Sever accepts the authorization. |
| 8367 | MockRead data_reads1[] = { |
| 8368 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8369 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8370 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8371 | }; |
| 8372 | |
| 8373 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8374 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8375 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8377 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8378 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8379 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8381 | |
| 8382 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8383 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8385 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8386 | ASSERT_TRUE(response); |
| 8387 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8388 | } |
| 8389 | } |
| 8390 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8391 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8392 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8393 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8396 | |
| 8397 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8398 | trans.read_buf_ = new IOBuffer(15); |
| 8399 | trans.read_buf_len_ = 15; |
| 8400 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8401 | |
| 8402 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8403 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8404 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8405 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8406 | response->response_time = base::Time::Now(); |
| 8407 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8408 | |
| 8409 | { // Setup state for response_.vary_data |
| 8410 | HttpRequestInfo request; |
| 8411 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8412 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8413 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8414 | request.extra_headers.SetHeader("Foo", "1"); |
| 8415 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8416 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8417 | } |
| 8418 | |
| 8419 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8420 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8421 | |
| 8422 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8423 | EXPECT_FALSE(trans.read_buf_); |
| 8424 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8425 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8426 | EXPECT_FALSE(response->auth_challenge); |
| 8427 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8428 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8429 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8430 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8431 | } |
| 8432 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8433 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8434 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8435 | HttpRequestInfo request; |
| 8436 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8437 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8438 | request.traffic_annotation = |
| 8439 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8440 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8443 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8444 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8445 | MockWrite( |
| 8446 | "GET / HTTP/1.1\r\n" |
| 8447 | "Host: www.example.org\r\n" |
| 8448 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8449 | }; |
| 8450 | |
| 8451 | MockRead data_reads[] = { |
| 8452 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8453 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8454 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8455 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8456 | }; |
| 8457 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8458 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8460 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8461 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8462 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8463 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8464 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8469 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8471 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8473 | |
| 8474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8475 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8477 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8479 | |
| 8480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8481 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8482 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8483 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8484 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8485 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8486 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8487 | } |
| 8488 | |
| 8489 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8490 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8491 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8492 | session_deps_.proxy_resolution_service = |
| 8493 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8494 | |
| 8495 | HttpRequestInfo request; |
| 8496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8497 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8498 | request.traffic_annotation = |
| 8499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8500 | |
| 8501 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8502 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8503 | "Host: www.example.org:443\r\n" |
| 8504 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8505 | }; |
| 8506 | |
| 8507 | MockRead proxy_reads[] = { |
| 8508 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8509 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8510 | }; |
| 8511 | |
| 8512 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8513 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8514 | "Host: www.example.org:443\r\n" |
| 8515 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8516 | MockWrite("GET / HTTP/1.1\r\n" |
| 8517 | "Host: www.example.org\r\n" |
| 8518 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8519 | }; |
| 8520 | |
| 8521 | MockRead data_reads[] = { |
| 8522 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8525 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8527 | }; |
| 8528 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8529 | StaticSocketDataProvider ssl_bad_certificate( |
| 8530 | proxy_reads, arraysize(proxy_reads), |
| 8531 | proxy_writes, arraysize(proxy_writes)); |
| 8532 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8533 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8534 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8535 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8536 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8537 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8538 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8540 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8541 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8542 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8543 | |
| 8544 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8545 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8546 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8549 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8550 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8552 | |
| 8553 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8554 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8556 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8558 | |
| 8559 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8563 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8564 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8565 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8566 | } |
| 8567 | } |
| 8568 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8569 | |
| 8570 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8571 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8572 | session_deps_.proxy_resolution_service = |
| 8573 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8574 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8575 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8576 | |
| 8577 | HttpRequestInfo request; |
| 8578 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8579 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8580 | request.traffic_annotation = |
| 8581 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8582 | |
| 8583 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8584 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8585 | "Host: www.example.org:443\r\n" |
| 8586 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8587 | MockWrite("GET / HTTP/1.1\r\n" |
| 8588 | "Host: www.example.org\r\n" |
| 8589 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8590 | }; |
| 8591 | |
| 8592 | MockRead data_reads[] = { |
| 8593 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8594 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8595 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8596 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8597 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8598 | }; |
| 8599 | |
| 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 proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8603 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8604 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8609 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8610 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8616 | |
| 8617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8618 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8620 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8621 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8622 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8623 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8624 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8625 | EXPECT_EQ(200, response->headers->response_code()); |
| 8626 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8627 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8628 | |
| 8629 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8630 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8631 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8632 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8633 | } |
| 8634 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8635 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8636 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8637 | session_deps_.proxy_resolution_service = |
| 8638 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8639 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8640 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8641 | |
| 8642 | HttpRequestInfo request; |
| 8643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8644 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8645 | request.traffic_annotation = |
| 8646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8647 | |
| 8648 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8649 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8650 | "Host: www.example.org:443\r\n" |
| 8651 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8652 | }; |
| 8653 | |
| 8654 | MockRead data_reads[] = { |
| 8655 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8656 | MockRead("Location: http://login.example.com/\r\n"), |
| 8657 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8658 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8659 | }; |
| 8660 | |
| 8661 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8662 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8663 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8664 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8666 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8668 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8673 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8675 | |
| 8676 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8677 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8678 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8679 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8680 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8681 | |
| 8682 | EXPECT_EQ(302, response->headers->response_code()); |
| 8683 | std::string url; |
| 8684 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8685 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8686 | |
| 8687 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8688 | // timing for the proxy connection instead of the connection to the host, |
| 8689 | // and no send / receive times. |
| 8690 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8691 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8692 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8693 | |
| 8694 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8695 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8696 | |
| 8697 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8698 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8699 | load_timing_info.proxy_resolve_end); |
| 8700 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8701 | load_timing_info.connect_timing.connect_start); |
| 8702 | ExpectConnectTimingHasTimes( |
| 8703 | load_timing_info.connect_timing, |
| 8704 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8705 | |
| 8706 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8707 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8708 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8709 | } |
| 8710 | |
| 8711 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8712 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8713 | session_deps_.proxy_resolution_service = |
| 8714 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8715 | |
| 8716 | HttpRequestInfo request; |
| 8717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8718 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8719 | request.traffic_annotation = |
| 8720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8721 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8722 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8723 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8724 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8725 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8726 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8727 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8728 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8729 | }; |
| 8730 | |
| 8731 | static const char* const kExtraHeaders[] = { |
| 8732 | "location", |
| 8733 | "http://login.example.com/", |
| 8734 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8735 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8736 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8737 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8738 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8739 | }; |
| 8740 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8741 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8742 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8743 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8744 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8745 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8749 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8753 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8754 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8756 | |
| 8757 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8758 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8759 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8760 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8761 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8762 | |
| 8763 | EXPECT_EQ(302, response->headers->response_code()); |
| 8764 | std::string url; |
| 8765 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8766 | EXPECT_EQ("http://login.example.com/", url); |
| 8767 | } |
| 8768 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8769 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8770 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8771 | session_deps_.proxy_resolution_service = |
| 8772 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8773 | |
| 8774 | HttpRequestInfo request; |
| 8775 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8776 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8777 | request.traffic_annotation = |
| 8778 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8779 | |
| 8780 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8781 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8782 | "Host: www.example.org:443\r\n" |
| 8783 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8784 | }; |
| 8785 | |
| 8786 | MockRead data_reads[] = { |
| 8787 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8788 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8789 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8790 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8791 | }; |
| 8792 | |
| 8793 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8794 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8795 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8796 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8798 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8799 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8800 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8801 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8805 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8807 | |
| 8808 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8809 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8810 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8811 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8812 | } |
| 8813 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8814 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8815 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8816 | session_deps_.proxy_resolution_service = |
| 8817 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8818 | |
| 8819 | HttpRequestInfo request; |
| 8820 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8821 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8822 | request.traffic_annotation = |
| 8823 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8824 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8825 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8826 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8827 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8828 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8829 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8830 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8831 | }; |
| 8832 | |
| 8833 | static const char* const kExtraHeaders[] = { |
| 8834 | "location", |
| 8835 | "http://login.example.com/", |
| 8836 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8837 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8838 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 8839 | SpdySerializedFrame body( |
| 8840 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8841 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8842 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8843 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8844 | }; |
| 8845 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8846 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8847 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8848 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8849 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8850 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8852 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8854 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8855 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8857 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8861 | |
| 8862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8863 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8864 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8865 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8866 | } |
| 8867 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8868 | // Test the request-challenge-retry sequence for basic auth, through |
| 8869 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8870 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8871 | HttpRequestInfo request; |
| 8872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8873 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8874 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8875 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8876 | request.traffic_annotation = |
| 8877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8878 | |
| 8879 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8880 | session_deps_.proxy_resolution_service = |
| 8881 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8882 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8883 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8885 | |
| 8886 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8887 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8888 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8889 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8890 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8891 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8893 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8894 | // be issuing -- the final header line contains the credentials. |
| 8895 | const char* const kAuthCredentials[] = { |
| 8896 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8897 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8898 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8899 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8900 | HostPortPair("www.example.org", 443))); |
| 8901 | // fetch https://www.example.org/ via HTTP |
| 8902 | const char get[] = |
| 8903 | "GET / HTTP/1.1\r\n" |
| 8904 | "Host: www.example.org\r\n" |
| 8905 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8906 | SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 8907 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8908 | |
| 8909 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8910 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8911 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8912 | }; |
| 8913 | |
| 8914 | // The proxy responds to the connect with a 407, using a persistent |
| 8915 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8916 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8917 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8918 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8919 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8920 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8921 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8922 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8923 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8924 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8925 | "Content-Length: 5\r\n\r\n"; |
| 8926 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8927 | SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 8928 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8929 | SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 8930 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8931 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8932 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8933 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8934 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8935 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8936 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8937 | }; |
| 8938 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8939 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8940 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8941 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8942 | // Negotiate SPDY to the proxy |
| 8943 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8944 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8945 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8946 | // Vanilla SSL to the server |
| 8947 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8949 | |
| 8950 | TestCompletionCallback callback1; |
| 8951 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8952 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8953 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8954 | |
| 8955 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8957 | |
| 8958 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8959 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8960 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8961 | log.GetEntries(&entries); |
| 8962 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8963 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8964 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8965 | ExpectLogContainsSomewhere( |
| 8966 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8967 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8968 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8969 | |
| 8970 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8971 | ASSERT_TRUE(response); |
| 8972 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8973 | EXPECT_EQ(407, response->headers->response_code()); |
| 8974 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8975 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8976 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8977 | |
| 8978 | TestCompletionCallback callback2; |
| 8979 | |
| 8980 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8981 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8983 | |
| 8984 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8985 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8986 | |
| 8987 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8988 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8989 | |
| 8990 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8991 | EXPECT_EQ(200, response->headers->response_code()); |
| 8992 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8994 | |
| 8995 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8996 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8997 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8998 | LoadTimingInfo load_timing_info; |
| 8999 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9000 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9001 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9002 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9003 | trans.reset(); |
| 9004 | session->CloseAllConnections(); |
| 9005 | } |
| 9006 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9007 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9008 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9009 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9010 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9011 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9012 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9013 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9014 | HttpRequestInfo request; |
| 9015 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9016 | request.traffic_annotation = |
| 9017 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9018 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9020 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9021 | push_request.method = "GET"; |
| 9022 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9023 | push_request.traffic_annotation = |
| 9024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9025 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9026 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9027 | session_deps_.proxy_resolution_service = |
| 9028 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9029 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9030 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9031 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9032 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9033 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9035 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9036 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9037 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9038 | SpdySerializedFrame stream2_priority( |
| 9039 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9040 | |
| 9041 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9042 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9043 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9044 | }; |
| 9045 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9046 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 9047 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9048 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9049 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9050 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9051 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9052 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9053 | |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame^] | 9054 | SpdySerializedFrame stream2_body( |
| 9055 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9056 | |
| 9057 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9058 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9059 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9060 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9061 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9062 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9063 | }; |
| 9064 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9065 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9066 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9067 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9068 | // Negotiate SPDY to the proxy |
| 9069 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9070 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9072 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9073 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9074 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9075 | TestCompletionCallback callback; |
| 9076 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9078 | |
| 9079 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9081 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9082 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9083 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9084 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9085 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9087 | |
| 9088 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9089 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9090 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9091 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9092 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9093 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9094 | |
| 9095 | EXPECT_EQ(200, response->headers->response_code()); |
| 9096 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9097 | |
| 9098 | std::string response_data; |
| 9099 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9101 | EXPECT_EQ("hello!", response_data); |
| 9102 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9103 | LoadTimingInfo load_timing_info; |
| 9104 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9105 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9106 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9107 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9108 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9109 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9110 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9111 | |
| 9112 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9114 | EXPECT_EQ("pushed", response_data); |
| 9115 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9116 | LoadTimingInfo push_load_timing_info; |
| 9117 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9118 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9119 | // The transactions should share a socket ID, despite being for different |
| 9120 | // origins. |
| 9121 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9122 | push_load_timing_info.socket_log_id); |
| 9123 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9124 | trans.reset(); |
| 9125 | push_trans.reset(); |
| 9126 | session->CloseAllConnections(); |
| 9127 | } |
| 9128 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9129 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9130 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9131 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9132 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9133 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9134 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9135 | HttpRequestInfo request; |
| 9136 | |
| 9137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9138 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9139 | request.traffic_annotation = |
| 9140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9141 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9142 | session_deps_.proxy_resolution_service = |
| 9143 | ProxyResolutionService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9144 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9145 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9146 | |
| 9147 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9148 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9151 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9152 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9153 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9154 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9155 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 9156 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9157 | |
| 9158 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9159 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9160 | }; |
| 9161 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9162 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9163 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9164 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9165 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9166 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9167 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9168 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9169 | |
| 9170 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9171 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9172 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9173 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9174 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9175 | }; |
| 9176 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9177 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9178 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9179 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9180 | // Negotiate SPDY to the proxy |
| 9181 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9182 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9184 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9185 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9186 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9187 | TestCompletionCallback callback; |
| 9188 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9190 | |
| 9191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9192 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9193 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9194 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9195 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9196 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9197 | |
| 9198 | EXPECT_EQ(200, response->headers->response_code()); |
| 9199 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9200 | |
| 9201 | std::string response_data; |
| 9202 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9204 | EXPECT_EQ("hello!", response_data); |
| 9205 | |
| 9206 | trans.reset(); |
| 9207 | session->CloseAllConnections(); |
| 9208 | } |
| 9209 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9210 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9211 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9212 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9213 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9214 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9215 | proxy_delegate->set_trusted_spdy_proxy( |
| 9216 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9217 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9218 | HttpRequestInfo request; |
| 9219 | |
| 9220 | request.method = "GET"; |
| 9221 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9222 | request.traffic_annotation = |
| 9223 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9224 | |
| 9225 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9226 | session_deps_.proxy_resolution_service = |
| 9227 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9228 | BoundTestNetLog log; |
| 9229 | session_deps_.net_log = log.bound().net_log(); |
| 9230 | |
| 9231 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9232 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9233 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9235 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9236 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9237 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9238 | SpdySerializedFrame stream2_priority( |
| 9239 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9240 | |
| 9241 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9242 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9243 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9244 | }; |
| 9245 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9246 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9247 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9248 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9249 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9250 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9251 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9252 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9253 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9254 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9255 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9256 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9257 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9258 | |
| 9259 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9260 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9261 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9262 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9263 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9264 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9265 | }; |
| 9266 | |
| 9267 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9268 | arraysize(spdy_writes)); |
| 9269 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9270 | // Negotiate SPDY to the proxy |
| 9271 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9272 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9274 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9275 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9276 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9277 | TestCompletionCallback callback; |
| 9278 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9280 | |
| 9281 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9282 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9283 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9284 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9285 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9286 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9287 | |
| 9288 | EXPECT_EQ(200, response->headers->response_code()); |
| 9289 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9290 | |
| 9291 | std::string response_data; |
| 9292 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9293 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9294 | EXPECT_EQ("hello!", response_data); |
| 9295 | |
| 9296 | trans.reset(); |
| 9297 | session->CloseAllConnections(); |
| 9298 | } |
| 9299 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9300 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9301 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9302 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9303 | session_deps_.proxy_resolution_service = |
| 9304 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9305 | |
| 9306 | HttpRequestInfo request; |
| 9307 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9308 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9309 | request.traffic_annotation = |
| 9310 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9311 | |
| 9312 | // Attempt to fetch the URL from a server with a bad cert |
| 9313 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9314 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9315 | "Host: www.example.org:443\r\n" |
| 9316 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9317 | }; |
| 9318 | |
| 9319 | MockRead bad_cert_reads[] = { |
| 9320 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9321 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9322 | }; |
| 9323 | |
| 9324 | // Attempt to fetch the URL with a good cert |
| 9325 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9326 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9327 | "Host: www.example.org:443\r\n" |
| 9328 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9329 | MockWrite("GET / HTTP/1.1\r\n" |
| 9330 | "Host: www.example.org\r\n" |
| 9331 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9332 | }; |
| 9333 | |
| 9334 | MockRead good_cert_reads[] = { |
| 9335 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9336 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9337 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9338 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9339 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9340 | }; |
| 9341 | |
| 9342 | StaticSocketDataProvider ssl_bad_certificate( |
| 9343 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9344 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9345 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9346 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9347 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9348 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9349 | |
| 9350 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9351 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9352 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9354 | |
| 9355 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9356 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9357 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9359 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9360 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9361 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9362 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9363 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9365 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9367 | |
| 9368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9369 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9371 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9373 | |
| 9374 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9377 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9378 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9379 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9380 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9381 | } |
| 9382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9383 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9384 | HttpRequestInfo request; |
| 9385 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9386 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9387 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9388 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9389 | request.traffic_annotation = |
| 9390 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9394 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9395 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9396 | MockWrite( |
| 9397 | "GET / HTTP/1.1\r\n" |
| 9398 | "Host: www.example.org\r\n" |
| 9399 | "Connection: keep-alive\r\n" |
| 9400 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9401 | }; |
| 9402 | |
| 9403 | // Lastly, the server responds with the actual content. |
| 9404 | MockRead data_reads[] = { |
| 9405 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9406 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9407 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9408 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9409 | }; |
| 9410 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9411 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9412 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9413 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9415 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9416 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9417 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9419 | |
| 9420 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9421 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9422 | } |
| 9423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9424 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9425 | HttpRequestInfo request; |
| 9426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9427 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9428 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9429 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9430 | request.traffic_annotation = |
| 9431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9432 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9433 | session_deps_.proxy_resolution_service = |
| 9434 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9435 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9436 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9437 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9438 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9439 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9440 | "Host: www.example.org:443\r\n" |
| 9441 | "Proxy-Connection: keep-alive\r\n" |
| 9442 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9443 | }; |
| 9444 | MockRead data_reads[] = { |
| 9445 | // Return an error, so the transaction stops here (this test isn't |
| 9446 | // interested in the rest). |
| 9447 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9448 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9449 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9450 | }; |
| 9451 | |
| 9452 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9453 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9454 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9455 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9456 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9457 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9458 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9460 | |
| 9461 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9462 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9463 | } |
| 9464 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9465 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9466 | HttpRequestInfo request; |
| 9467 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9468 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9469 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9470 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9471 | request.traffic_annotation = |
| 9472 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9476 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9477 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9478 | MockWrite( |
| 9479 | "GET / HTTP/1.1\r\n" |
| 9480 | "Host: www.example.org\r\n" |
| 9481 | "Connection: keep-alive\r\n" |
| 9482 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9483 | }; |
| 9484 | |
| 9485 | // Lastly, the server responds with the actual content. |
| 9486 | MockRead data_reads[] = { |
| 9487 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9488 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9489 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9490 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9491 | }; |
| 9492 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9493 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9494 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9495 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9497 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9498 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9499 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9501 | |
| 9502 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9503 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9504 | } |
| 9505 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9506 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9507 | HttpRequestInfo request; |
| 9508 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9509 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9510 | request.traffic_annotation = |
| 9511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9515 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9516 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9517 | MockWrite( |
| 9518 | "POST / HTTP/1.1\r\n" |
| 9519 | "Host: www.example.org\r\n" |
| 9520 | "Connection: keep-alive\r\n" |
| 9521 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9522 | }; |
| 9523 | |
| 9524 | // Lastly, the server responds with the actual content. |
| 9525 | MockRead data_reads[] = { |
| 9526 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9527 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9528 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9529 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9530 | }; |
| 9531 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9532 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9533 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9534 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9535 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9536 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9538 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9540 | |
| 9541 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9542 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9543 | } |
| 9544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9545 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9546 | HttpRequestInfo request; |
| 9547 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9548 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9549 | request.traffic_annotation = |
| 9550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9554 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9555 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9556 | MockWrite( |
| 9557 | "PUT / HTTP/1.1\r\n" |
| 9558 | "Host: www.example.org\r\n" |
| 9559 | "Connection: keep-alive\r\n" |
| 9560 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9561 | }; |
| 9562 | |
| 9563 | // Lastly, the server responds with the actual content. |
| 9564 | MockRead data_reads[] = { |
| 9565 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9566 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9567 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9568 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9569 | }; |
| 9570 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9571 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9572 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9573 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9574 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9575 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9576 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9577 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9578 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9579 | |
| 9580 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9581 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9582 | } |
| 9583 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9584 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9585 | HttpRequestInfo request; |
| 9586 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9587 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9588 | request.traffic_annotation = |
| 9589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9593 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9594 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9595 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9596 | "Host: www.example.org\r\n" |
| 9597 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9598 | }; |
| 9599 | |
| 9600 | // Lastly, the server responds with the actual content. |
| 9601 | MockRead data_reads[] = { |
| 9602 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9603 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9604 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9605 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9606 | }; |
| 9607 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9608 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9609 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9610 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9611 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9612 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9613 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9614 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9615 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9616 | |
| 9617 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9619 | } |
| 9620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9621 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9622 | HttpRequestInfo request; |
| 9623 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9624 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9625 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9626 | request.traffic_annotation = |
| 9627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9628 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9629 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9630 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9631 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9632 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9633 | MockWrite( |
| 9634 | "GET / HTTP/1.1\r\n" |
| 9635 | "Host: www.example.org\r\n" |
| 9636 | "Connection: keep-alive\r\n" |
| 9637 | "Pragma: no-cache\r\n" |
| 9638 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9639 | }; |
| 9640 | |
| 9641 | // Lastly, the server responds with the actual content. |
| 9642 | MockRead data_reads[] = { |
| 9643 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9644 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9645 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9646 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9647 | }; |
| 9648 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9649 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9650 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9652 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9653 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9654 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9655 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9657 | |
| 9658 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9660 | } |
| 9661 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9662 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9663 | HttpRequestInfo request; |
| 9664 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9665 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9666 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9667 | request.traffic_annotation = |
| 9668 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9669 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9672 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9673 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9674 | MockWrite( |
| 9675 | "GET / HTTP/1.1\r\n" |
| 9676 | "Host: www.example.org\r\n" |
| 9677 | "Connection: keep-alive\r\n" |
| 9678 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9679 | }; |
| 9680 | |
| 9681 | // Lastly, the server responds with the actual content. |
| 9682 | MockRead data_reads[] = { |
| 9683 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9684 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9685 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9686 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9687 | }; |
| 9688 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9689 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9690 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9693 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9697 | |
| 9698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9699 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9700 | } |
| 9701 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9702 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9703 | HttpRequestInfo request; |
| 9704 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9705 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9706 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9707 | request.traffic_annotation = |
| 9708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9709 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9710 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9711 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9712 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9713 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9714 | MockWrite( |
| 9715 | "GET / HTTP/1.1\r\n" |
| 9716 | "Host: www.example.org\r\n" |
| 9717 | "Connection: keep-alive\r\n" |
| 9718 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9719 | }; |
| 9720 | |
| 9721 | // Lastly, the server responds with the actual content. |
| 9722 | MockRead data_reads[] = { |
| 9723 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9724 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9725 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9726 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9727 | }; |
| 9728 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9729 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9730 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9733 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9734 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9735 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9737 | |
| 9738 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9740 | } |
| 9741 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9742 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9743 | HttpRequestInfo request; |
| 9744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9745 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9746 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9747 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9748 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9749 | request.traffic_annotation = |
| 9750 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9754 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9755 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9756 | MockWrite( |
| 9757 | "GET / HTTP/1.1\r\n" |
| 9758 | "Host: www.example.org\r\n" |
| 9759 | "Connection: keep-alive\r\n" |
| 9760 | "referer: www.foo.com\r\n" |
| 9761 | "hEllo: Kitty\r\n" |
| 9762 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9763 | }; |
| 9764 | |
| 9765 | // Lastly, the server responds with the actual content. |
| 9766 | MockRead data_reads[] = { |
| 9767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9768 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9769 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9771 | }; |
| 9772 | |
| 9773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9774 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9777 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9781 | |
| 9782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9783 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9784 | } |
| 9785 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9786 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9787 | HttpRequestInfo request; |
| 9788 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9789 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9790 | request.traffic_annotation = |
| 9791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9792 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9793 | session_deps_.proxy_resolution_service = |
| 9794 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9795 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9796 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9797 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9798 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9799 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9800 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9801 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9802 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9803 | |
| 9804 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9805 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9806 | MockWrite( |
| 9807 | "GET / HTTP/1.1\r\n" |
| 9808 | "Host: www.example.org\r\n" |
| 9809 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9810 | |
| 9811 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9812 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9813 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9814 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9815 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9816 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9817 | }; |
| 9818 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9819 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9820 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9823 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9825 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9827 | |
| 9828 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9832 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9833 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9834 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9835 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9836 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9837 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9838 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9839 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9840 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9841 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9843 | EXPECT_EQ("Payload", response_text); |
| 9844 | } |
| 9845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9846 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9847 | HttpRequestInfo request; |
| 9848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9849 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9850 | request.traffic_annotation = |
| 9851 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9852 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9853 | session_deps_.proxy_resolution_service = |
| 9854 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9855 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9856 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9860 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9861 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9862 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9863 | |
| 9864 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9865 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9866 | arraysize(write_buffer)), |
| 9867 | MockWrite( |
| 9868 | "GET / HTTP/1.1\r\n" |
| 9869 | "Host: www.example.org\r\n" |
| 9870 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9871 | |
| 9872 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9873 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9874 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9875 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9876 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9877 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9878 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9879 | }; |
| 9880 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9881 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9882 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9884 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9885 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9888 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9889 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9890 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9892 | |
| 9893 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9895 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9896 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9897 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9898 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9899 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9901 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9902 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9903 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9904 | |
| 9905 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9906 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9908 | EXPECT_EQ("Payload", response_text); |
| 9909 | } |
| 9910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9911 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9912 | HttpRequestInfo request; |
| 9913 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9914 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9915 | request.traffic_annotation = |
| 9916 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9917 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9918 | session_deps_.proxy_resolution_service = |
| 9919 | ProxyResolutionService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9920 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9921 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9922 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9925 | |
| 9926 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9927 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9928 | |
| 9929 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9930 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9931 | MockWrite( |
| 9932 | "GET / HTTP/1.1\r\n" |
| 9933 | "Host: www.example.org\r\n" |
| 9934 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9935 | |
| 9936 | MockRead data_reads[] = { |
| 9937 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9938 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9939 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9940 | MockRead("Payload"), |
| 9941 | MockRead(SYNCHRONOUS, OK) |
| 9942 | }; |
| 9943 | |
| 9944 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9945 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9947 | |
| 9948 | TestCompletionCallback callback; |
| 9949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9950 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9952 | |
| 9953 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9954 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9956 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9957 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9958 | |
| 9959 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9960 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9961 | TestLoadTimingNotReused(load_timing_info, |
| 9962 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9963 | |
| 9964 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9965 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9967 | EXPECT_EQ("Payload", response_text); |
| 9968 | } |
| 9969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9970 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9971 | HttpRequestInfo request; |
| 9972 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9973 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9974 | request.traffic_annotation = |
| 9975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9976 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9977 | session_deps_.proxy_resolution_service = |
| 9978 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9979 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9980 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9981 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9984 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9985 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9986 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9987 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9988 | 0x05, // Version |
| 9989 | 0x01, // Command (CONNECT) |
| 9990 | 0x00, // Reserved. |
| 9991 | 0x03, // Address type (DOMAINNAME). |
| 9992 | 0x0F, // Length of domain (15) |
| 9993 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9994 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9995 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9996 | const char kSOCKS5OkResponse[] = |
| 9997 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9998 | |
| 9999 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10000 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10001 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10002 | MockWrite( |
| 10003 | "GET / HTTP/1.1\r\n" |
| 10004 | "Host: www.example.org\r\n" |
| 10005 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10006 | |
| 10007 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10008 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10009 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10010 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10011 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10012 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10013 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10014 | }; |
| 10015 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10016 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 10017 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10018 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10019 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10020 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10022 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10024 | |
| 10025 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10026 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10028 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10029 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10030 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10031 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10032 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10033 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10034 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10035 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10036 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10037 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10038 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10039 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10040 | EXPECT_EQ("Payload", response_text); |
| 10041 | } |
| 10042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10043 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10044 | HttpRequestInfo request; |
| 10045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10046 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10047 | request.traffic_annotation = |
| 10048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10049 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10050 | session_deps_.proxy_resolution_service = |
| 10051 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10052 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10053 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10054 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10056 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10057 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10058 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10059 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10060 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10061 | 0x05, // Version |
| 10062 | 0x01, // Command (CONNECT) |
| 10063 | 0x00, // Reserved. |
| 10064 | 0x03, // Address type (DOMAINNAME). |
| 10065 | 0x0F, // Length of domain (15) |
| 10066 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10067 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10068 | }; |
| 10069 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10070 | const char kSOCKS5OkResponse[] = |
| 10071 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10072 | |
| 10073 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10074 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10075 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10076 | arraysize(kSOCKS5OkRequest)), |
| 10077 | MockWrite( |
| 10078 | "GET / HTTP/1.1\r\n" |
| 10079 | "Host: www.example.org\r\n" |
| 10080 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10081 | |
| 10082 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10083 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10084 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 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"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10088 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10089 | }; |
| 10090 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 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] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10094 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10095 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10098 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10099 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10100 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10102 | |
| 10103 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10104 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10105 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10106 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10107 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10108 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10109 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10110 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10111 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10112 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10113 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10114 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10115 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10116 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10118 | EXPECT_EQ("Payload", response_text); |
| 10119 | } |
| 10120 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10121 | namespace { |
| 10122 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10123 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10124 | |
| 10125 | struct GroupNameTest { |
| 10126 | std::string proxy_server; |
| 10127 | std::string url; |
| 10128 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10129 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10130 | }; |
| 10131 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10132 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10133 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10135 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10136 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10137 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10138 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10139 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10140 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10141 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10142 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10143 | |
| 10144 | return session; |
| 10145 | } |
| 10146 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10147 | int GroupNameTransactionHelper(const std::string& url, |
| 10148 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10149 | HttpRequestInfo request; |
| 10150 | request.method = "GET"; |
| 10151 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10152 | request.traffic_annotation = |
| 10153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10157 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10158 | |
| 10159 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10160 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10161 | } |
| 10162 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10163 | } // namespace |
| 10164 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10165 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10166 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10167 | { |
| 10168 | "", // unused |
| 10169 | "http://www.example.org/direct", |
| 10170 | "www.example.org:80", |
| 10171 | false, |
| 10172 | }, |
| 10173 | { |
| 10174 | "", // unused |
| 10175 | "http://[2001:1418:13:1::25]/direct", |
| 10176 | "[2001:1418:13:1::25]:80", |
| 10177 | false, |
| 10178 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10179 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10180 | // SSL Tests |
| 10181 | { |
| 10182 | "", // unused |
| 10183 | "https://www.example.org/direct_ssl", |
| 10184 | "ssl/www.example.org:443", |
| 10185 | true, |
| 10186 | }, |
| 10187 | { |
| 10188 | "", // unused |
| 10189 | "https://[2001:1418:13:1::25]/direct", |
| 10190 | "ssl/[2001:1418:13:1::25]:443", |
| 10191 | true, |
| 10192 | }, |
| 10193 | { |
| 10194 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10195 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10196 | "ssl/host.with.alternate:443", |
| 10197 | true, |
| 10198 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10199 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10200 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10201 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10202 | session_deps_.proxy_resolution_service = |
| 10203 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10204 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10205 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10206 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10207 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10208 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10209 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10210 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10211 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10212 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10213 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10214 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10215 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10216 | |
| 10217 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10218 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10219 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10220 | EXPECT_EQ(tests[i].expected_group_name, |
| 10221 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10222 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10223 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10224 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10225 | } |
| 10226 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10227 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10228 | // When SSL proxy is not in use, socket must be requested from |
| 10229 | // |transport_conn_pool|. |
| 10230 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10231 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10232 | } |
| 10233 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10234 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10235 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10236 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10237 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10238 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10239 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10240 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10241 | // SSL Tests |
| 10242 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10243 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10244 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10245 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10246 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10247 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10248 | "http_proxy", "https://host.with.alternate/direct", |
| 10249 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10250 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10251 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10252 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10253 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10254 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10255 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10256 | }; |
| 10257 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10258 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10259 | session_deps_.proxy_resolution_service = |
| 10260 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10261 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10262 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10263 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10264 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10265 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10266 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10267 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10268 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10269 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10270 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10271 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10272 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10273 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10274 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10275 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10276 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10277 | |
| 10278 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10279 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10280 | if (tests[i].ssl) |
| 10281 | EXPECT_EQ(tests[i].expected_group_name, |
| 10282 | ssl_conn_pool->last_group_name_received()); |
| 10283 | else |
| 10284 | EXPECT_EQ(tests[i].expected_group_name, |
| 10285 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10286 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10287 | } |
| 10288 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10289 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10290 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10291 | { |
| 10292 | "socks4://socks_proxy:1080", |
| 10293 | "http://www.example.org/socks4_direct", |
| 10294 | "socks4/www.example.org:80", |
| 10295 | false, |
| 10296 | }, |
| 10297 | { |
| 10298 | "socks5://socks_proxy:1080", |
| 10299 | "http://www.example.org/socks5_direct", |
| 10300 | "socks5/www.example.org:80", |
| 10301 | false, |
| 10302 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10303 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10304 | // SSL Tests |
| 10305 | { |
| 10306 | "socks4://socks_proxy:1080", |
| 10307 | "https://www.example.org/socks4_ssl", |
| 10308 | "socks4/ssl/www.example.org:443", |
| 10309 | true, |
| 10310 | }, |
| 10311 | { |
| 10312 | "socks5://socks_proxy:1080", |
| 10313 | "https://www.example.org/socks5_ssl", |
| 10314 | "socks5/ssl/www.example.org:443", |
| 10315 | true, |
| 10316 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10317 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10318 | { |
| 10319 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10320 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10321 | "socks4/ssl/host.with.alternate:443", |
| 10322 | true, |
| 10323 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10324 | }; |
| 10325 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10326 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10327 | session_deps_.proxy_resolution_service = |
| 10328 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10329 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10330 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10331 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10332 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10333 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10334 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10335 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10336 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10337 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10338 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10339 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10340 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10341 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10342 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10343 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10344 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10347 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10348 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10349 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10350 | if (tests[i].ssl) |
| 10351 | EXPECT_EQ(tests[i].expected_group_name, |
| 10352 | ssl_conn_pool->last_group_name_received()); |
| 10353 | else |
| 10354 | EXPECT_EQ(tests[i].expected_group_name, |
| 10355 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10356 | } |
| 10357 | } |
| 10358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10359 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10360 | HttpRequestInfo request; |
| 10361 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10362 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10363 | request.traffic_annotation = |
| 10364 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10365 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10366 | session_deps_.proxy_resolution_service = |
| 10367 | ProxyResolutionService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10368 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10369 | // This simulates failure resolving all hostnames; that means we will fail |
| 10370 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10371 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10372 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10374 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10375 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10376 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10380 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10382 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10383 | } |
| 10384 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10385 | // Base test to make sure that when the load flags for a request specify to |
| 10386 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10387 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10388 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10389 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10390 | HttpRequestInfo request_info; |
| 10391 | request_info.method = "GET"; |
| 10392 | request_info.load_flags = load_flags; |
| 10393 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10394 | request_info.traffic_annotation = |
| 10395 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10396 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10397 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10398 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10399 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10401 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10402 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10403 | // 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] | 10404 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10405 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10406 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10407 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10408 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10409 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10410 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10414 | |
| 10415 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10416 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10417 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10418 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10419 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10420 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10421 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10422 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10423 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10424 | // 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] | 10425 | // we can tell if the next lookup hit the cache, or the "network". |
| 10426 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10427 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10428 | |
| 10429 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10430 | // 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] | 10431 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10432 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10434 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10435 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10436 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10437 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10438 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10439 | |
| 10440 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10441 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10442 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10443 | } |
| 10444 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10445 | // There are multiple load flags that should trigger the host cache bypass. |
| 10446 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10447 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10448 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 10449 | } |
| 10450 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10451 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10452 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 10453 | } |
| 10454 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10455 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10456 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 10457 | } |
| 10458 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10459 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10460 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10461 | HttpRequestInfo request; |
| 10462 | request.method = "GET"; |
| 10463 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10464 | request.traffic_annotation = |
| 10465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10466 | |
| 10467 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10468 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10469 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10470 | StaticSocketDataProvider data(NULL, 0, |
| 10471 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10472 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10475 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10478 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10479 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10481 | |
| 10482 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10483 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10484 | |
| 10485 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10486 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10487 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10488 | } |
| 10489 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10490 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10491 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10492 | HttpRequestInfo request; |
| 10493 | request.method = "GET"; |
| 10494 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10495 | request.traffic_annotation = |
| 10496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10497 | |
| 10498 | MockRead data_reads[] = { |
| 10499 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10500 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10501 | }; |
| 10502 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10503 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10504 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10507 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10509 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10510 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10511 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10512 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10513 | |
| 10514 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10515 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10517 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10518 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10519 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10520 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10521 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10522 | |
| 10523 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10524 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10525 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10526 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10527 | |
| 10528 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10529 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10530 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10531 | } |
| 10532 | |
| 10533 | // Make sure that a dropped connection while draining the body for auth |
| 10534 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10535 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10536 | HttpRequestInfo request; |
| 10537 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10538 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10539 | request.traffic_annotation = |
| 10540 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10541 | |
| 10542 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10543 | MockWrite( |
| 10544 | "GET / HTTP/1.1\r\n" |
| 10545 | "Host: www.example.org\r\n" |
| 10546 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10547 | }; |
| 10548 | |
| 10549 | MockRead data_reads1[] = { |
| 10550 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10551 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10552 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10553 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10554 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10555 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10556 | }; |
| 10557 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10559 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10562 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10563 | // be issuing -- the final header line contains the credentials. |
| 10564 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10565 | MockWrite( |
| 10566 | "GET / HTTP/1.1\r\n" |
| 10567 | "Host: www.example.org\r\n" |
| 10568 | "Connection: keep-alive\r\n" |
| 10569 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10570 | }; |
| 10571 | |
| 10572 | // Lastly, the server responds with the actual content. |
| 10573 | MockRead data_reads2[] = { |
| 10574 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10575 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10576 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10577 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10578 | }; |
| 10579 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10580 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10581 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10582 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10585 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10589 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10591 | |
| 10592 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10596 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10597 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10599 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10601 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10602 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10603 | |
| 10604 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10605 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10607 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10608 | ASSERT_TRUE(response); |
| 10609 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10610 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10611 | } |
| 10612 | |
| 10613 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10614 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10615 | session_deps_.proxy_resolution_service = |
| 10616 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10617 | |
| 10618 | HttpRequestInfo request; |
| 10619 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10620 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10621 | request.traffic_annotation = |
| 10622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10623 | |
| 10624 | MockRead proxy_reads[] = { |
| 10625 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10626 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10627 | }; |
| 10628 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10629 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10630 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10631 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10635 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10636 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10637 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10638 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10642 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10644 | |
| 10645 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10646 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10647 | } |
| 10648 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10649 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10650 | HttpRequestInfo request; |
| 10651 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10652 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10653 | request.traffic_annotation = |
| 10654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10655 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10657 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10658 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10659 | MockRead data_reads[] = { |
| 10660 | 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] | 10661 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10662 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10663 | |
| 10664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10667 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10671 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10672 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10674 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10675 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10676 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10677 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10678 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10679 | |
| 10680 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10681 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10682 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10683 | } |
| 10684 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10685 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10686 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10687 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10688 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10689 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10690 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10692 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10693 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10694 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10695 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10696 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10697 | |
| 10698 | HttpRequestInfo request; |
| 10699 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10700 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10701 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10702 | request.traffic_annotation = |
| 10703 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10707 | |
| 10708 | MockRead data_reads[] = { |
| 10709 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10710 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10711 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10712 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10713 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10714 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10716 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10720 | |
| 10721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10722 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10724 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10725 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10726 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10727 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10728 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10729 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10730 | } |
| 10731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10732 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10733 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10734 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10735 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10736 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10737 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10738 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10739 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10740 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10741 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10742 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10743 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10744 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10745 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10746 | |
| 10747 | HttpRequestInfo request; |
| 10748 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10749 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10750 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10751 | request.traffic_annotation = |
| 10752 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10753 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10754 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10756 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10757 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10758 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10761 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10763 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10765 | |
| 10766 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10767 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10768 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10769 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10770 | } |
| 10771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10772 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10773 | class FakeUploadElementReader : public UploadElementReader { |
| 10774 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10775 | FakeUploadElementReader() = default; |
| 10776 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10777 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10778 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10779 | |
| 10780 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10781 | int Init(CompletionOnceCallback callback) override { |
| 10782 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10783 | return ERR_IO_PENDING; |
| 10784 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10785 | uint64_t GetContentLength() const override { return 0; } |
| 10786 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10787 | int Read(IOBuffer* buf, |
| 10788 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10789 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10790 | return ERR_FAILED; |
| 10791 | } |
| 10792 | |
| 10793 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10794 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10795 | }; |
| 10796 | |
| 10797 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10798 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10799 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10800 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10801 | |
| 10802 | HttpRequestInfo request; |
| 10803 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10804 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10805 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10806 | request.traffic_annotation = |
| 10807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10810 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10811 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10812 | |
| 10813 | StaticSocketDataProvider data; |
| 10814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10815 | |
| 10816 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10817 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10819 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10820 | |
| 10821 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10822 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10823 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10824 | |
| 10825 | // Return Init()'s result after the transaction gets destroyed. |
| 10826 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10827 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10828 | } |
| 10829 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10830 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10831 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10832 | HttpRequestInfo request; |
| 10833 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10834 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10835 | request.traffic_annotation = |
| 10836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10837 | |
| 10838 | // First transaction will request a resource and receive a Basic challenge |
| 10839 | // with realm="first_realm". |
| 10840 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10841 | MockWrite( |
| 10842 | "GET / HTTP/1.1\r\n" |
| 10843 | "Host: www.example.org\r\n" |
| 10844 | "Connection: keep-alive\r\n" |
| 10845 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10846 | }; |
| 10847 | MockRead data_reads1[] = { |
| 10848 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10849 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10850 | "\r\n"), |
| 10851 | }; |
| 10852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10853 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10854 | // for first_realm. The server will reject and provide a challenge with |
| 10855 | // second_realm. |
| 10856 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10857 | MockWrite( |
| 10858 | "GET / HTTP/1.1\r\n" |
| 10859 | "Host: www.example.org\r\n" |
| 10860 | "Connection: keep-alive\r\n" |
| 10861 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10862 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10863 | }; |
| 10864 | MockRead data_reads2[] = { |
| 10865 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10866 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10867 | "\r\n"), |
| 10868 | }; |
| 10869 | |
| 10870 | // This again fails, and goes back to first_realm. Make sure that the |
| 10871 | // entry is removed from cache. |
| 10872 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10873 | MockWrite( |
| 10874 | "GET / HTTP/1.1\r\n" |
| 10875 | "Host: www.example.org\r\n" |
| 10876 | "Connection: keep-alive\r\n" |
| 10877 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10878 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10879 | }; |
| 10880 | MockRead data_reads3[] = { |
| 10881 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10882 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10883 | "\r\n"), |
| 10884 | }; |
| 10885 | |
| 10886 | // Try one last time (with the correct password) and get the resource. |
| 10887 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10888 | MockWrite( |
| 10889 | "GET / HTTP/1.1\r\n" |
| 10890 | "Host: www.example.org\r\n" |
| 10891 | "Connection: keep-alive\r\n" |
| 10892 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10893 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10894 | }; |
| 10895 | MockRead data_reads4[] = { |
| 10896 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10897 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10898 | "Content-Length: 5\r\n" |
| 10899 | "\r\n" |
| 10900 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10901 | }; |
| 10902 | |
| 10903 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10904 | data_writes1, arraysize(data_writes1)); |
| 10905 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10906 | data_writes2, arraysize(data_writes2)); |
| 10907 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10908 | data_writes3, arraysize(data_writes3)); |
| 10909 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10910 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10911 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10912 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10913 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10914 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10916 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10917 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10919 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10920 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10921 | // Issue the first request with Authorize headers. There should be a |
| 10922 | // password prompt for first_realm waiting to be filled in after the |
| 10923 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10924 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10926 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10927 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10928 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10929 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10930 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10931 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10932 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10933 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10934 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10935 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10936 | |
| 10937 | // Issue the second request with an incorrect password. There should be a |
| 10938 | // password prompt for second_realm waiting to be filled in after the |
| 10939 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10940 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10941 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10942 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10944 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10945 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10946 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10947 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10948 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10949 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10950 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10951 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10952 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10953 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10954 | |
| 10955 | // Issue the third request with another incorrect password. There should be |
| 10956 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10957 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10958 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10959 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10960 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10961 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10963 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10964 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10965 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10966 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10967 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10968 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10969 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10970 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10971 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10972 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10973 | |
| 10974 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10975 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10976 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10977 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10979 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10980 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10981 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10982 | ASSERT_TRUE(response); |
| 10983 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10984 | } |
| 10985 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10986 | // Regression test for https://crbug.com/754395. |
| 10987 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10988 | MockRead data_reads[] = { |
| 10989 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10990 | MockRead(kAlternativeServiceHttpHeader), |
| 10991 | MockRead("\r\n"), |
| 10992 | MockRead("hello world"), |
| 10993 | MockRead(SYNCHRONOUS, OK), |
| 10994 | }; |
| 10995 | |
| 10996 | HttpRequestInfo request; |
| 10997 | request.method = "GET"; |
| 10998 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10999 | request.traffic_annotation = |
| 11000 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11001 | |
| 11002 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11003 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11004 | |
| 11005 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11006 | ssl.ssl_info.cert = |
| 11007 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11008 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11009 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11011 | |
| 11012 | TestCompletionCallback callback; |
| 11013 | |
| 11014 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11016 | |
| 11017 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11019 | |
| 11020 | url::SchemeHostPort test_server(request.url); |
| 11021 | HttpServerProperties* http_server_properties = |
| 11022 | session->http_server_properties(); |
| 11023 | EXPECT_TRUE( |
| 11024 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11025 | |
| 11026 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11027 | |
| 11028 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11029 | ASSERT_TRUE(response); |
| 11030 | ASSERT_TRUE(response->headers); |
| 11031 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11032 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11033 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11034 | |
| 11035 | std::string response_data; |
| 11036 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11037 | EXPECT_EQ("hello world", response_data); |
| 11038 | |
| 11039 | EXPECT_TRUE( |
| 11040 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11041 | } |
| 11042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11043 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11044 | MockRead data_reads[] = { |
| 11045 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11046 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11047 | MockRead("\r\n"), |
| 11048 | MockRead("hello world"), |
| 11049 | MockRead(SYNCHRONOUS, OK), |
| 11050 | }; |
| 11051 | |
| 11052 | HttpRequestInfo request; |
| 11053 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11054 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11055 | request.traffic_annotation = |
| 11056 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11057 | |
| 11058 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11059 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11060 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11061 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11062 | ssl.ssl_info.cert = |
| 11063 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11064 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11065 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11066 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11067 | TestCompletionCallback callback; |
| 11068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11074 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11075 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11076 | HttpServerProperties* http_server_properties = |
| 11077 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11078 | EXPECT_TRUE( |
| 11079 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11080 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11081 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11083 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11084 | ASSERT_TRUE(response); |
| 11085 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11086 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11087 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11088 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11089 | |
| 11090 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11091 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11092 | EXPECT_EQ("hello world", response_data); |
| 11093 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11094 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11095 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11096 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11097 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11098 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11099 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11100 | } |
| 11101 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11102 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11103 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11104 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11105 | MockRead data_reads[] = { |
| 11106 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11107 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11108 | MockRead("\r\n"), |
| 11109 | MockRead("hello world"), |
| 11110 | MockRead(SYNCHRONOUS, OK), |
| 11111 | }; |
| 11112 | |
| 11113 | HttpRequestInfo request; |
| 11114 | request.method = "GET"; |
| 11115 | request.url = GURL("http://www.example.org/"); |
| 11116 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11117 | request.traffic_annotation = |
| 11118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11119 | |
| 11120 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 11121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11122 | |
| 11123 | TestCompletionCallback callback; |
| 11124 | |
| 11125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11127 | |
| 11128 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11129 | HttpServerProperties* http_server_properties = |
| 11130 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11131 | EXPECT_TRUE( |
| 11132 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11133 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11134 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11135 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11136 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11138 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11139 | ASSERT_TRUE(response); |
| 11140 | ASSERT_TRUE(response->headers); |
| 11141 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11142 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11143 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11144 | |
| 11145 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11146 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11147 | EXPECT_EQ("hello world", response_data); |
| 11148 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11149 | EXPECT_TRUE( |
| 11150 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11151 | } |
| 11152 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11153 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11154 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11155 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11156 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11157 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11158 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11159 | HttpRequestInfo request; |
| 11160 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11161 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11162 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11163 | request.traffic_annotation = |
| 11164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11165 | |
| 11166 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11167 | StaticSocketDataProvider first_data; |
| 11168 | first_data.set_connect_data(mock_connect); |
| 11169 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11170 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11171 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11173 | |
| 11174 | MockRead data_reads[] = { |
| 11175 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11176 | MockRead(ASYNC, OK), |
| 11177 | }; |
| 11178 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11179 | 0); |
| 11180 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11181 | |
| 11182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11183 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11184 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11185 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11186 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11187 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11188 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11189 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11190 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11192 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11193 | TestCompletionCallback callback; |
| 11194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11195 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11196 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11197 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11198 | } |
| 11199 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11200 | // Regression test for https://crbug.com/615497: |
| 11201 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11202 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11203 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11204 | HttpRequestInfo request; |
| 11205 | request.method = "GET"; |
| 11206 | request.url = GURL("http://www.example.org/"); |
| 11207 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11208 | request.traffic_annotation = |
| 11209 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11210 | |
| 11211 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11212 | StaticSocketDataProvider first_data; |
| 11213 | first_data.set_connect_data(mock_connect); |
| 11214 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11215 | |
| 11216 | MockRead data_reads[] = { |
| 11217 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11218 | MockRead(ASYNC, OK), |
| 11219 | }; |
| 11220 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 11221 | 0); |
| 11222 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11223 | |
| 11224 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11225 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11226 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11227 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11228 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11229 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11230 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11231 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11234 | TestCompletionCallback callback; |
| 11235 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11236 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11237 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11238 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11239 | } |
| 11240 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11241 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11242 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11244 | HttpServerProperties* http_server_properties = |
| 11245 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11246 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11247 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11248 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11249 | http_server_properties->SetQuicAlternativeService( |
| 11250 | test_server, alternative_service, expiration, |
| 11251 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11252 | EXPECT_EQ( |
| 11253 | 1u, |
| 11254 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11255 | |
| 11256 | // Send a clear header. |
| 11257 | MockRead data_reads[] = { |
| 11258 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11259 | MockRead("Alt-Svc: clear\r\n"), |
| 11260 | MockRead("\r\n"), |
| 11261 | MockRead("hello world"), |
| 11262 | MockRead(SYNCHRONOUS, OK), |
| 11263 | }; |
| 11264 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 11265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11266 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11267 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11268 | ssl.ssl_info.cert = |
| 11269 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11270 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11272 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11273 | HttpRequestInfo request; |
| 11274 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11275 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11276 | request.traffic_annotation = |
| 11277 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11278 | |
| 11279 | TestCompletionCallback callback; |
| 11280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11281 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11282 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11283 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11284 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11286 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11287 | ASSERT_TRUE(response); |
| 11288 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11289 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11290 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11291 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11292 | |
| 11293 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11294 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11295 | EXPECT_EQ("hello world", response_data); |
| 11296 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11297 | EXPECT_TRUE( |
| 11298 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11299 | } |
| 11300 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11301 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11302 | MockRead data_reads[] = { |
| 11303 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11304 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11305 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11306 | MockRead("hello world"), |
| 11307 | MockRead(SYNCHRONOUS, OK), |
| 11308 | }; |
| 11309 | |
| 11310 | HttpRequestInfo request; |
| 11311 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11312 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11313 | request.traffic_annotation = |
| 11314 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11315 | |
| 11316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11318 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11319 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11320 | ssl.ssl_info.cert = |
| 11321 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11322 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11323 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11324 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11325 | TestCompletionCallback callback; |
| 11326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11329 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11330 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11332 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11333 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11334 | HttpServerProperties* http_server_properties = |
| 11335 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11336 | EXPECT_TRUE( |
| 11337 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11338 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11339 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11340 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11341 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11342 | ASSERT_TRUE(response); |
| 11343 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11344 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11345 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11346 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11347 | |
| 11348 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11349 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11350 | EXPECT_EQ("hello world", response_data); |
| 11351 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11352 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11353 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11354 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11355 | |
| 11356 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11357 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11358 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11359 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11360 | 1234); |
| 11361 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11362 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11363 | } |
| 11364 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11365 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11366 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11367 | HostPortPair alternative("alternative.example.org", 443); |
| 11368 | std::string origin_url = "https://origin.example.org:443"; |
| 11369 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11370 | |
| 11371 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11372 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11373 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11375 | |
| 11376 | // HTTP/1.1 data for request. |
| 11377 | MockWrite http_writes[] = { |
| 11378 | MockWrite("GET / HTTP/1.1\r\n" |
| 11379 | "Host: alternative.example.org\r\n" |
| 11380 | "Connection: keep-alive\r\n\r\n"), |
| 11381 | }; |
| 11382 | |
| 11383 | MockRead http_reads[] = { |
| 11384 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11385 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11386 | "Content-Length: 40\r\n\r\n" |
| 11387 | "first HTTP/1.1 response from alternative"), |
| 11388 | }; |
| 11389 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11390 | http_writes, arraysize(http_writes)); |
| 11391 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11392 | |
| 11393 | StaticSocketDataProvider data_refused; |
| 11394 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11395 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11396 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11397 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11398 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11399 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11400 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11401 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11402 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11403 | http_server_properties->SetQuicAlternativeService( |
| 11404 | server, alternative_service, expiration, |
| 11405 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11406 | // Mark the QUIC alternative service as broken. |
| 11407 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11408 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11409 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11411 | request.method = "GET"; |
| 11412 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11413 | request.traffic_annotation = |
| 11414 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11415 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11416 | TestCompletionCallback callback; |
| 11417 | NetErrorDetails details; |
| 11418 | EXPECT_FALSE(details.quic_broken); |
| 11419 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11420 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11421 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11422 | EXPECT_TRUE(details.quic_broken); |
| 11423 | } |
| 11424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11425 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11426 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11427 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11428 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11429 | std::string origin_url = "https://origin.example.org:443"; |
| 11430 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11431 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11432 | |
| 11433 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11434 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11435 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11436 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11437 | |
| 11438 | // HTTP/1.1 data for request. |
| 11439 | MockWrite http_writes[] = { |
| 11440 | MockWrite("GET / HTTP/1.1\r\n" |
| 11441 | "Host: alternative1.example.org\r\n" |
| 11442 | "Connection: keep-alive\r\n\r\n"), |
| 11443 | }; |
| 11444 | |
| 11445 | MockRead http_reads[] = { |
| 11446 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11447 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11448 | "Content-Length: 40\r\n\r\n" |
| 11449 | "first HTTP/1.1 response from alternative1"), |
| 11450 | }; |
| 11451 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11452 | http_writes, arraysize(http_writes)); |
| 11453 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11454 | |
| 11455 | StaticSocketDataProvider data_refused; |
| 11456 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11457 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11458 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11460 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11461 | session->http_server_properties(); |
| 11462 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11463 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11464 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11465 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11466 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11467 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11468 | alternative_service_info_vector.push_back( |
| 11469 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11470 | alternative_service1, expiration, |
| 11471 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11472 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11473 | alternative_service_info_vector.push_back( |
| 11474 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11475 | alternative_service2, expiration, |
| 11476 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11477 | |
| 11478 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11479 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11480 | |
| 11481 | // Mark one of the QUIC alternative service as broken. |
| 11482 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11483 | EXPECT_EQ(2u, |
| 11484 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11485 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11486 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11488 | request.method = "GET"; |
| 11489 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11490 | request.traffic_annotation = |
| 11491 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11492 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11493 | TestCompletionCallback callback; |
| 11494 | NetErrorDetails details; |
| 11495 | EXPECT_FALSE(details.quic_broken); |
| 11496 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11497 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11498 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11499 | EXPECT_FALSE(details.quic_broken); |
| 11500 | } |
| 11501 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11502 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11503 | HttpRequestInfo request; |
| 11504 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11505 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11506 | request.traffic_annotation = |
| 11507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11508 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11509 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11510 | StaticSocketDataProvider first_data; |
| 11511 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11512 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11513 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11514 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11516 | |
| 11517 | MockRead data_reads[] = { |
| 11518 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11519 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11520 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11521 | }; |
| 11522 | StaticSocketDataProvider second_data( |
| 11523 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11524 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11527 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11528 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11529 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11530 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11531 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11532 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11533 | // Port is ignored by MockConnect anyway. |
| 11534 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11535 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11536 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11537 | http_server_properties->SetHttp2AlternativeService( |
| 11538 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11540 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11541 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11545 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11546 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11547 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11548 | ASSERT_TRUE(response); |
| 11549 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11550 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11551 | |
| 11552 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11553 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11554 | EXPECT_EQ("hello world", response_data); |
| 11555 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11556 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11557 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11558 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11559 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11560 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11561 | EXPECT_TRUE( |
| 11562 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11563 | } |
| 11564 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11565 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11566 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11567 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11568 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11569 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11570 | HttpRequestInfo restricted_port_request; |
| 11571 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11572 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11573 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11574 | restricted_port_request.traffic_annotation = |
| 11575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11576 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11577 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11578 | StaticSocketDataProvider first_data; |
| 11579 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11580 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11581 | |
| 11582 | MockRead data_reads[] = { |
| 11583 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11584 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11585 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11586 | }; |
| 11587 | StaticSocketDataProvider second_data( |
| 11588 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11589 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11590 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11591 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11595 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11596 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11597 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11598 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11599 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11600 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11601 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11602 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11603 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11604 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11607 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11608 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11609 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11610 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11612 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11613 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11614 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11615 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11616 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11617 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11618 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11619 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11620 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11621 | |
| 11622 | HttpRequestInfo restricted_port_request; |
| 11623 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11624 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11625 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11626 | restricted_port_request.traffic_annotation = |
| 11627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11628 | |
| 11629 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11630 | StaticSocketDataProvider first_data; |
| 11631 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11632 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11633 | |
| 11634 | MockRead data_reads[] = { |
| 11635 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11636 | MockRead("hello world"), |
| 11637 | MockRead(ASYNC, OK), |
| 11638 | }; |
| 11639 | StaticSocketDataProvider second_data( |
| 11640 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11641 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11642 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11643 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11644 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11647 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11648 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11649 | session->http_server_properties(); |
| 11650 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11651 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11652 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11653 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11654 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11655 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11656 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11658 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11659 | TestCompletionCallback callback; |
| 11660 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11661 | EXPECT_EQ(ERR_IO_PENDING, |
| 11662 | trans.Start(&restricted_port_request, callback.callback(), |
| 11663 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11664 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11665 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11666 | } |
| 11667 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11668 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11669 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11670 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11671 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11672 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11673 | HttpRequestInfo restricted_port_request; |
| 11674 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11675 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11676 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11677 | restricted_port_request.traffic_annotation = |
| 11678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11679 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11680 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11681 | StaticSocketDataProvider first_data; |
| 11682 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11683 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11684 | |
| 11685 | MockRead data_reads[] = { |
| 11686 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11687 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11688 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11689 | }; |
| 11690 | StaticSocketDataProvider second_data( |
| 11691 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11692 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11693 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11694 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11696 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11698 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11699 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11700 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11701 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11702 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11703 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11704 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11705 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11706 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11707 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11709 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11710 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11711 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11712 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11713 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11715 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11716 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11717 | } |
| 11718 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11719 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11720 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11721 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11722 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11723 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11724 | HttpRequestInfo unrestricted_port_request; |
| 11725 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11726 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11727 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11728 | unrestricted_port_request.traffic_annotation = |
| 11729 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11730 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11731 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11732 | StaticSocketDataProvider first_data; |
| 11733 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11734 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11735 | |
| 11736 | MockRead data_reads[] = { |
| 11737 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11738 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11739 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11740 | }; |
| 11741 | StaticSocketDataProvider second_data( |
| 11742 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11743 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11744 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11745 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11749 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11750 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11751 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11752 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11753 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11754 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11755 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11756 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11757 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11758 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11761 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11763 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11764 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11765 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11766 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11767 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11768 | } |
| 11769 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11770 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11771 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11772 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11773 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11774 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11775 | HttpRequestInfo unrestricted_port_request; |
| 11776 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11777 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11778 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11779 | unrestricted_port_request.traffic_annotation = |
| 11780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11781 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11782 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11783 | StaticSocketDataProvider first_data; |
| 11784 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11785 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11786 | |
| 11787 | MockRead data_reads[] = { |
| 11788 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11789 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11790 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11791 | }; |
| 11792 | StaticSocketDataProvider second_data( |
| 11793 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11794 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11795 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11796 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11800 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11801 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11802 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11803 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11804 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11805 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11806 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11807 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11808 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11809 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11812 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11814 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11815 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11817 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11818 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11819 | } |
| 11820 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11821 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11822 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11823 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11824 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11825 | HttpRequestInfo request; |
| 11826 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11827 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11828 | request.traffic_annotation = |
| 11829 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11830 | |
| 11831 | // The alternate protocol request will error out before we attempt to connect, |
| 11832 | // so only the standard HTTP request will try to connect. |
| 11833 | MockRead data_reads[] = { |
| 11834 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11835 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11836 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11837 | }; |
| 11838 | StaticSocketDataProvider data( |
| 11839 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11840 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11841 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11843 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11844 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11845 | session->http_server_properties(); |
| 11846 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11847 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11848 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11849 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11850 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11851 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11853 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11854 | TestCompletionCallback callback; |
| 11855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11858 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11859 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11861 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11862 | ASSERT_TRUE(response); |
| 11863 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11864 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11865 | |
| 11866 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11867 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11868 | EXPECT_EQ("hello world", response_data); |
| 11869 | } |
| 11870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11871 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11872 | HttpRequestInfo request; |
| 11873 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11874 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11875 | request.traffic_annotation = |
| 11876 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11877 | |
| 11878 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11879 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11880 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11881 | MockRead("\r\n"), |
| 11882 | MockRead("hello world"), |
| 11883 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11884 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11885 | |
| 11886 | StaticSocketDataProvider first_transaction( |
| 11887 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11888 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11889 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11890 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11892 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11893 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11894 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11895 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11896 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11897 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11898 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11899 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11900 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11901 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11902 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11903 | }; |
| 11904 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11905 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11906 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11907 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11908 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11909 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11910 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11911 | NULL, 0, NULL, 0); |
| 11912 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11913 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11914 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11915 | &hanging_non_alternate_protocol_socket); |
| 11916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11917 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11918 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11920 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11921 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11923 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11925 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11926 | |
| 11927 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11928 | ASSERT_TRUE(response); |
| 11929 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11930 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11931 | |
| 11932 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11933 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11934 | EXPECT_EQ("hello world", response_data); |
| 11935 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11936 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11937 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11939 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11941 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11942 | |
| 11943 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11944 | ASSERT_TRUE(response); |
| 11945 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11946 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11947 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11948 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11949 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11950 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11951 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11952 | } |
| 11953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11954 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11955 | HttpRequestInfo request; |
| 11956 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11957 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11958 | request.traffic_annotation = |
| 11959 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11960 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11961 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11962 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11963 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11964 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11965 | MockRead("\r\n"), |
| 11966 | MockRead("hello world"), |
| 11967 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11968 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11969 | }; |
| 11970 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11971 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11972 | 0); |
| 11973 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11974 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11975 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11976 | ssl_http11.ssl_info.cert = |
| 11977 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11978 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11979 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11980 | |
| 11981 | // Second transaction starts an alternative and a non-alternative Job. |
| 11982 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11983 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11984 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11985 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11986 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11987 | |
| 11988 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11989 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11990 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11991 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11992 | // Third transaction starts an alternative and a non-alternative job. |
| 11993 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11994 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11995 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11996 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11997 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11998 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11999 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12000 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12001 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12002 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12003 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12004 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12005 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12006 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12007 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12008 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12009 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12010 | }; |
| 12011 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12012 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12013 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12014 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12015 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12016 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12017 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12018 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 12019 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12020 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12023 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12024 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12025 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12026 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12028 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12029 | |
| 12030 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12031 | ASSERT_TRUE(response); |
| 12032 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12033 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12034 | |
| 12035 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12036 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12037 | EXPECT_EQ("hello world", response_data); |
| 12038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12039 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12040 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12041 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12044 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12045 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12046 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12047 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12048 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12049 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12050 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12051 | |
| 12052 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12053 | ASSERT_TRUE(response); |
| 12054 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12055 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12056 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12057 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12058 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12059 | EXPECT_EQ("hello!", response_data); |
| 12060 | |
| 12061 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12062 | ASSERT_TRUE(response); |
| 12063 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12064 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12065 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12066 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12067 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12068 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12069 | } |
| 12070 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12071 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12072 | HttpRequestInfo request; |
| 12073 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12074 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12075 | request.traffic_annotation = |
| 12076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12077 | |
| 12078 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12079 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12080 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12081 | MockRead("\r\n"), |
| 12082 | MockRead("hello world"), |
| 12083 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12084 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12085 | }; |
| 12086 | |
| 12087 | StaticSocketDataProvider first_transaction( |
| 12088 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12089 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12090 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12091 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12092 | ssl.ssl_info.cert = |
| 12093 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12094 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12095 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12096 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12097 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12098 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 12099 | NULL, 0, NULL, 0); |
| 12100 | hanging_alternate_protocol_socket.set_connect_data( |
| 12101 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12102 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12103 | &hanging_alternate_protocol_socket); |
| 12104 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12105 | // 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] | 12106 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 12107 | NULL, 0); |
| 12108 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12111 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12112 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12114 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12115 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12117 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12119 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12120 | |
| 12121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12122 | ASSERT_TRUE(response); |
| 12123 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12124 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12125 | |
| 12126 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12127 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12128 | EXPECT_EQ("hello world", response_data); |
| 12129 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12130 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12131 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12132 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12133 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12135 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12136 | |
| 12137 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12138 | ASSERT_TRUE(response); |
| 12139 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12140 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12141 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12142 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12143 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12144 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12145 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12146 | } |
| 12147 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12148 | class CapturingProxyResolver : public ProxyResolver { |
| 12149 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12150 | CapturingProxyResolver() = default; |
| 12151 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12152 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12153 | int GetProxyForURL(const GURL& url, |
| 12154 | ProxyInfo* results, |
| 12155 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12156 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12157 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12158 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12159 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12160 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12161 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12162 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12163 | } |
| 12164 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12165 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12166 | |
| 12167 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12168 | std::vector<GURL> resolved_; |
| 12169 | |
| 12170 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12171 | }; |
| 12172 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12173 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12174 | public: |
| 12175 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12176 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12177 | |
| 12178 | int CreateProxyResolver( |
| 12179 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12180 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12181 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12182 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12183 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12184 | return OK; |
| 12185 | } |
| 12186 | |
| 12187 | private: |
| 12188 | ProxyResolver* resolver_; |
| 12189 | }; |
| 12190 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12191 | // Test that proxy is resolved using the origin url, |
| 12192 | // regardless of the alternative server. |
| 12193 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12194 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12195 | ProxyConfig proxy_config; |
| 12196 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12197 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 12198 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12199 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12200 | |
| 12201 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12202 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12203 | &capturing_proxy_resolver); |
| 12204 | |
| 12205 | TestNetLog net_log; |
| 12206 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12207 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12208 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12209 | &net_log); |
| 12210 | |
| 12211 | session_deps_.net_log = &net_log; |
| 12212 | |
| 12213 | // Configure alternative service with a hostname that is not bypassed by the |
| 12214 | // proxy. |
| 12215 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12216 | HttpServerProperties* http_server_properties = |
| 12217 | session->http_server_properties(); |
| 12218 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12219 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12220 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12221 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12222 | http_server_properties->SetHttp2AlternativeService( |
| 12223 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12224 | |
| 12225 | // Non-alternative job should hang. |
| 12226 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 12227 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 12228 | nullptr, 0); |
| 12229 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12230 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12231 | &hanging_alternate_protocol_socket); |
| 12232 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12233 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12234 | |
| 12235 | HttpRequestInfo request; |
| 12236 | request.method = "GET"; |
| 12237 | request.url = GURL("https://www.example.org/"); |
| 12238 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12239 | request.traffic_annotation = |
| 12240 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12241 | |
| 12242 | SpdySerializedFrame req( |
| 12243 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12244 | |
| 12245 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12246 | |
| 12247 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12248 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12249 | MockRead spdy_reads[] = { |
| 12250 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12251 | }; |
| 12252 | |
| 12253 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12254 | arraysize(spdy_writes)); |
| 12255 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12256 | |
| 12257 | TestCompletionCallback callback; |
| 12258 | |
| 12259 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12260 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12261 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12262 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12263 | |
| 12264 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12265 | ASSERT_TRUE(response); |
| 12266 | ASSERT_TRUE(response->headers); |
| 12267 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12268 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12269 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12270 | |
| 12271 | std::string response_data; |
| 12272 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12273 | EXPECT_EQ("hello!", response_data); |
| 12274 | |
| 12275 | // Origin host bypasses proxy, no resolution should have happened. |
| 12276 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12277 | } |
| 12278 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12279 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12280 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12281 | proxy_config.set_auto_detect(true); |
| 12282 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12283 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12284 | CapturingProxyResolver capturing_proxy_resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 12285 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12286 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 12287 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12288 | &capturing_proxy_resolver), |
| 12289 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12290 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12291 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12292 | |
| 12293 | HttpRequestInfo request; |
| 12294 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12295 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12296 | request.traffic_annotation = |
| 12297 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12298 | |
| 12299 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12300 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12301 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12302 | MockRead("\r\n"), |
| 12303 | MockRead("hello world"), |
| 12304 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12305 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12306 | }; |
| 12307 | |
| 12308 | StaticSocketDataProvider first_transaction( |
| 12309 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12310 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12311 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12312 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12314 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12315 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12316 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12317 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12318 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12319 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12320 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12321 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12322 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12323 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12324 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12325 | }; |
| 12326 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12327 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12328 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12329 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12330 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12331 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12332 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12333 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12334 | }; |
| 12335 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12336 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12337 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12338 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12339 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12340 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12341 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12342 | NULL, 0, NULL, 0); |
| 12343 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12344 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12345 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12346 | &hanging_non_alternate_protocol_socket); |
| 12347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12348 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12351 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12352 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12354 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12356 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12357 | |
| 12358 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12359 | ASSERT_TRUE(response); |
| 12360 | ASSERT_TRUE(response->headers); |
| 12361 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12362 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12363 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12364 | |
| 12365 | std::string response_data; |
| 12366 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12367 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12368 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12369 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12370 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12371 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12372 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12373 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12374 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12375 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12376 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12377 | ASSERT_TRUE(response); |
| 12378 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12379 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12380 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12381 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12382 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12383 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12384 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12385 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12386 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12387 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12388 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12389 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12390 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12391 | LoadTimingInfo load_timing_info; |
| 12392 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12393 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12394 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12395 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12396 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12397 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12398 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12399 | HttpRequestInfo request; |
| 12400 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12401 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12402 | request.traffic_annotation = |
| 12403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12404 | |
| 12405 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12406 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12407 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12408 | MockRead("\r\n"), |
| 12409 | MockRead("hello world"), |
| 12410 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12411 | }; |
| 12412 | |
| 12413 | StaticSocketDataProvider first_transaction( |
| 12414 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12415 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12416 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12417 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12419 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12420 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12421 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12422 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12423 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12424 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12425 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12426 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12427 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12428 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12429 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12430 | }; |
| 12431 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12432 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12433 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12434 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12435 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12436 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12437 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12438 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12439 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12440 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12441 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12443 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12444 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12445 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12446 | |
| 12447 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12448 | ASSERT_TRUE(response); |
| 12449 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12450 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12451 | |
| 12452 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12453 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12454 | EXPECT_EQ("hello world", response_data); |
| 12455 | |
| 12456 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12457 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12458 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12459 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12460 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12461 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12462 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12463 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12464 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12466 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12468 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12469 | |
| 12470 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12471 | ASSERT_TRUE(response); |
| 12472 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12473 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12474 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12475 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12476 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12477 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12478 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12479 | } |
| 12480 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12481 | // GenerateAuthToken is a mighty big test. |
| 12482 | // It tests all permutation of GenerateAuthToken behavior: |
| 12483 | // - Synchronous and Asynchronous completion. |
| 12484 | // - OK or error on completion. |
| 12485 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12486 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12487 | // - Non-authenticating and authenticating backend. |
| 12488 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12489 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12490 | // problems generating an auth token for an authenticating proxy, we don't |
| 12491 | // need to test all permutations of the backend server). |
| 12492 | // |
| 12493 | // The test proceeds by going over each of the configuration cases, and |
| 12494 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12495 | // specifies both the configuration for the test as well as the expectations |
| 12496 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12497 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12498 | static const char kServer[] = "http://www.example.com"; |
| 12499 | static const char kSecureServer[] = "https://www.example.com"; |
| 12500 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12501 | |
| 12502 | enum AuthTiming { |
| 12503 | AUTH_NONE, |
| 12504 | AUTH_SYNC, |
| 12505 | AUTH_ASYNC, |
| 12506 | }; |
| 12507 | |
| 12508 | const MockWrite kGet( |
| 12509 | "GET / HTTP/1.1\r\n" |
| 12510 | "Host: www.example.com\r\n" |
| 12511 | "Connection: keep-alive\r\n\r\n"); |
| 12512 | const MockWrite kGetProxy( |
| 12513 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12514 | "Host: www.example.com\r\n" |
| 12515 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12516 | const MockWrite kGetAuth( |
| 12517 | "GET / HTTP/1.1\r\n" |
| 12518 | "Host: www.example.com\r\n" |
| 12519 | "Connection: keep-alive\r\n" |
| 12520 | "Authorization: auth_token\r\n\r\n"); |
| 12521 | const MockWrite kGetProxyAuth( |
| 12522 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12523 | "Host: www.example.com\r\n" |
| 12524 | "Proxy-Connection: keep-alive\r\n" |
| 12525 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12526 | const MockWrite kGetAuthThroughProxy( |
| 12527 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12528 | "Host: www.example.com\r\n" |
| 12529 | "Proxy-Connection: keep-alive\r\n" |
| 12530 | "Authorization: auth_token\r\n\r\n"); |
| 12531 | const MockWrite kGetAuthWithProxyAuth( |
| 12532 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12533 | "Host: www.example.com\r\n" |
| 12534 | "Proxy-Connection: keep-alive\r\n" |
| 12535 | "Proxy-Authorization: auth_token\r\n" |
| 12536 | "Authorization: auth_token\r\n\r\n"); |
| 12537 | const MockWrite kConnect( |
| 12538 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12539 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12540 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12541 | const MockWrite kConnectProxyAuth( |
| 12542 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12543 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12544 | "Proxy-Connection: keep-alive\r\n" |
| 12545 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12546 | |
| 12547 | const MockRead kSuccess( |
| 12548 | "HTTP/1.1 200 OK\r\n" |
| 12549 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12550 | "Content-Length: 3\r\n\r\n" |
| 12551 | "Yes"); |
| 12552 | const MockRead kFailure( |
| 12553 | "Should not be called."); |
| 12554 | const MockRead kServerChallenge( |
| 12555 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12556 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12557 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12558 | "Content-Length: 14\r\n\r\n" |
| 12559 | "Unauthorized\r\n"); |
| 12560 | const MockRead kProxyChallenge( |
| 12561 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12562 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12563 | "Proxy-Connection: close\r\n" |
| 12564 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12565 | "Content-Length: 14\r\n\r\n" |
| 12566 | "Unauthorized\r\n"); |
| 12567 | const MockRead kProxyConnected( |
| 12568 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12569 | |
| 12570 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12571 | // no constructors, but the C++ compiler on Windows warns about |
| 12572 | // unspecified data in compound literals. So, moved to using constructors, |
| 12573 | // and TestRound's created with the default constructor should not be used. |
| 12574 | struct TestRound { |
| 12575 | TestRound() |
| 12576 | : expected_rv(ERR_UNEXPECTED), |
| 12577 | extra_write(NULL), |
| 12578 | extra_read(NULL) { |
| 12579 | } |
| 12580 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12581 | int expected_rv_arg) |
| 12582 | : write(write_arg), |
| 12583 | read(read_arg), |
| 12584 | expected_rv(expected_rv_arg), |
| 12585 | extra_write(NULL), |
| 12586 | extra_read(NULL) { |
| 12587 | } |
| 12588 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12589 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12590 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12591 | : write(write_arg), |
| 12592 | read(read_arg), |
| 12593 | expected_rv(expected_rv_arg), |
| 12594 | extra_write(extra_write_arg), |
| 12595 | extra_read(extra_read_arg) { |
| 12596 | } |
| 12597 | MockWrite write; |
| 12598 | MockRead read; |
| 12599 | int expected_rv; |
| 12600 | const MockWrite* extra_write; |
| 12601 | const MockRead* extra_read; |
| 12602 | }; |
| 12603 | |
| 12604 | static const int kNoSSL = 500; |
| 12605 | |
| 12606 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12607 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12608 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12609 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12610 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12611 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12612 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12613 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12614 | int num_auth_rounds; |
| 12615 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12616 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12617 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12618 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12619 | {__LINE__, |
| 12620 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12621 | AUTH_NONE, |
| 12622 | OK, |
| 12623 | kServer, |
| 12624 | AUTH_NONE, |
| 12625 | OK, |
| 12626 | 1, |
| 12627 | kNoSSL, |
| 12628 | {TestRound(kGet, kSuccess, OK)}}, |
| 12629 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12630 | {__LINE__, |
| 12631 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12632 | AUTH_NONE, |
| 12633 | OK, |
| 12634 | kServer, |
| 12635 | AUTH_SYNC, |
| 12636 | OK, |
| 12637 | 2, |
| 12638 | kNoSSL, |
| 12639 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12640 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12641 | {__LINE__, |
| 12642 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12643 | AUTH_NONE, |
| 12644 | OK, |
| 12645 | kServer, |
| 12646 | AUTH_SYNC, |
| 12647 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12648 | 3, |
| 12649 | kNoSSL, |
| 12650 | {TestRound(kGet, kServerChallenge, OK), |
| 12651 | TestRound(kGet, kServerChallenge, OK), |
| 12652 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12653 | {__LINE__, |
| 12654 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12655 | AUTH_NONE, |
| 12656 | OK, |
| 12657 | kServer, |
| 12658 | AUTH_SYNC, |
| 12659 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12660 | 2, |
| 12661 | kNoSSL, |
| 12662 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12663 | {__LINE__, |
| 12664 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12665 | AUTH_NONE, |
| 12666 | OK, |
| 12667 | kServer, |
| 12668 | AUTH_SYNC, |
| 12669 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12670 | 2, |
| 12671 | kNoSSL, |
| 12672 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12673 | {__LINE__, |
| 12674 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12675 | AUTH_SYNC, |
| 12676 | ERR_FAILED, |
| 12677 | kServer, |
| 12678 | AUTH_NONE, |
| 12679 | OK, |
| 12680 | 2, |
| 12681 | kNoSSL, |
| 12682 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12683 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12684 | {__LINE__, |
| 12685 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12686 | AUTH_ASYNC, |
| 12687 | ERR_FAILED, |
| 12688 | kServer, |
| 12689 | AUTH_NONE, |
| 12690 | OK, |
| 12691 | 2, |
| 12692 | kNoSSL, |
| 12693 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12694 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12695 | {__LINE__, |
| 12696 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12697 | AUTH_NONE, |
| 12698 | OK, |
| 12699 | kServer, |
| 12700 | AUTH_SYNC, |
| 12701 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12702 | 2, |
| 12703 | kNoSSL, |
| 12704 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12705 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12706 | {__LINE__, |
| 12707 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12708 | AUTH_NONE, |
| 12709 | OK, |
| 12710 | kServer, |
| 12711 | AUTH_ASYNC, |
| 12712 | ERR_FAILED, |
| 12713 | 2, |
| 12714 | kNoSSL, |
| 12715 | {TestRound(kGet, kServerChallenge, OK), |
| 12716 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12717 | {__LINE__, |
| 12718 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12719 | AUTH_NONE, |
| 12720 | OK, |
| 12721 | kServer, |
| 12722 | AUTH_ASYNC, |
| 12723 | OK, |
| 12724 | 2, |
| 12725 | kNoSSL, |
| 12726 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12727 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12728 | {__LINE__, |
| 12729 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12730 | AUTH_NONE, |
| 12731 | OK, |
| 12732 | kServer, |
| 12733 | AUTH_ASYNC, |
| 12734 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12735 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12736 | kNoSSL, |
| 12737 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12738 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12739 | TestRound(kGet, kServerChallenge, OK), |
| 12740 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12741 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12742 | {__LINE__, |
| 12743 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12744 | AUTH_NONE, |
| 12745 | OK, |
| 12746 | kServer, |
| 12747 | AUTH_NONE, |
| 12748 | OK, |
| 12749 | 1, |
| 12750 | kNoSSL, |
| 12751 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12752 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12753 | {__LINE__, |
| 12754 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12755 | AUTH_NONE, |
| 12756 | OK, |
| 12757 | kServer, |
| 12758 | AUTH_SYNC, |
| 12759 | OK, |
| 12760 | 2, |
| 12761 | kNoSSL, |
| 12762 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12763 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12764 | {__LINE__, |
| 12765 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12766 | AUTH_NONE, |
| 12767 | OK, |
| 12768 | kServer, |
| 12769 | AUTH_SYNC, |
| 12770 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12771 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12772 | kNoSSL, |
| 12773 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12774 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12775 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12776 | {__LINE__, |
| 12777 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12778 | AUTH_NONE, |
| 12779 | OK, |
| 12780 | kServer, |
| 12781 | AUTH_ASYNC, |
| 12782 | OK, |
| 12783 | 2, |
| 12784 | kNoSSL, |
| 12785 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12786 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12787 | {__LINE__, |
| 12788 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12789 | AUTH_NONE, |
| 12790 | OK, |
| 12791 | kServer, |
| 12792 | AUTH_ASYNC, |
| 12793 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12794 | 2, |
| 12795 | kNoSSL, |
| 12796 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12797 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12798 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12799 | {__LINE__, |
| 12800 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12801 | AUTH_SYNC, |
| 12802 | OK, |
| 12803 | kServer, |
| 12804 | AUTH_NONE, |
| 12805 | OK, |
| 12806 | 2, |
| 12807 | kNoSSL, |
| 12808 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12809 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12810 | {__LINE__, |
| 12811 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12812 | AUTH_SYNC, |
| 12813 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12814 | kServer, |
| 12815 | AUTH_NONE, |
| 12816 | OK, |
| 12817 | 2, |
| 12818 | kNoSSL, |
| 12819 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12820 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12821 | {__LINE__, |
| 12822 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12823 | AUTH_ASYNC, |
| 12824 | OK, |
| 12825 | kServer, |
| 12826 | AUTH_NONE, |
| 12827 | OK, |
| 12828 | 2, |
| 12829 | kNoSSL, |
| 12830 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12831 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12832 | {__LINE__, |
| 12833 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12834 | AUTH_ASYNC, |
| 12835 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12836 | kServer, |
| 12837 | AUTH_NONE, |
| 12838 | OK, |
| 12839 | 2, |
| 12840 | kNoSSL, |
| 12841 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12842 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12843 | {__LINE__, |
| 12844 | kProxy, |
| 12845 | AUTH_ASYNC, |
| 12846 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12847 | kServer, |
| 12848 | AUTH_NONE, |
| 12849 | OK, |
| 12850 | 3, |
| 12851 | kNoSSL, |
| 12852 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12853 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12854 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12855 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12856 | {__LINE__, |
| 12857 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12858 | AUTH_SYNC, |
| 12859 | OK, |
| 12860 | kServer, |
| 12861 | AUTH_SYNC, |
| 12862 | OK, |
| 12863 | 3, |
| 12864 | kNoSSL, |
| 12865 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12866 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12867 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12868 | {__LINE__, |
| 12869 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12870 | AUTH_SYNC, |
| 12871 | OK, |
| 12872 | kServer, |
| 12873 | AUTH_SYNC, |
| 12874 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12875 | 3, |
| 12876 | kNoSSL, |
| 12877 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12878 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12879 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 12883 | OK, |
| 12884 | kServer, |
| 12885 | AUTH_SYNC, |
| 12886 | OK, |
| 12887 | 3, |
| 12888 | kNoSSL, |
| 12889 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12890 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12891 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12892 | {__LINE__, |
| 12893 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12894 | AUTH_ASYNC, |
| 12895 | OK, |
| 12896 | kServer, |
| 12897 | AUTH_SYNC, |
| 12898 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12899 | 3, |
| 12900 | kNoSSL, |
| 12901 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12902 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12903 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12904 | {__LINE__, |
| 12905 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12906 | AUTH_SYNC, |
| 12907 | OK, |
| 12908 | kServer, |
| 12909 | AUTH_ASYNC, |
| 12910 | OK, |
| 12911 | 3, |
| 12912 | kNoSSL, |
| 12913 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12914 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12915 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12916 | {__LINE__, |
| 12917 | kProxy, |
| 12918 | AUTH_SYNC, |
| 12919 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12920 | kServer, |
| 12921 | AUTH_ASYNC, |
| 12922 | OK, |
| 12923 | 4, |
| 12924 | kNoSSL, |
| 12925 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12926 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12927 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12928 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12929 | {__LINE__, |
| 12930 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12931 | AUTH_SYNC, |
| 12932 | OK, |
| 12933 | kServer, |
| 12934 | AUTH_ASYNC, |
| 12935 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12936 | 3, |
| 12937 | kNoSSL, |
| 12938 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12939 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12940 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12941 | {__LINE__, |
| 12942 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12943 | AUTH_ASYNC, |
| 12944 | OK, |
| 12945 | kServer, |
| 12946 | AUTH_ASYNC, |
| 12947 | OK, |
| 12948 | 3, |
| 12949 | kNoSSL, |
| 12950 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12951 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12952 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12953 | {__LINE__, |
| 12954 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12955 | AUTH_ASYNC, |
| 12956 | OK, |
| 12957 | kServer, |
| 12958 | AUTH_ASYNC, |
| 12959 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12960 | 3, |
| 12961 | kNoSSL, |
| 12962 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12963 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12964 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12965 | {__LINE__, |
| 12966 | kProxy, |
| 12967 | AUTH_ASYNC, |
| 12968 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12969 | kServer, |
| 12970 | AUTH_ASYNC, |
| 12971 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12972 | 4, |
| 12973 | kNoSSL, |
| 12974 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12975 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12976 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12977 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12978 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12979 | {__LINE__, |
| 12980 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12981 | AUTH_NONE, |
| 12982 | OK, |
| 12983 | kSecureServer, |
| 12984 | AUTH_NONE, |
| 12985 | OK, |
| 12986 | 1, |
| 12987 | 0, |
| 12988 | {TestRound(kGet, kSuccess, OK)}}, |
| 12989 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12990 | {__LINE__, |
| 12991 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12992 | AUTH_NONE, |
| 12993 | OK, |
| 12994 | kSecureServer, |
| 12995 | AUTH_SYNC, |
| 12996 | OK, |
| 12997 | 2, |
| 12998 | 0, |
| 12999 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13000 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13001 | {__LINE__, |
| 13002 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13003 | AUTH_NONE, |
| 13004 | OK, |
| 13005 | kSecureServer, |
| 13006 | AUTH_SYNC, |
| 13007 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13008 | 2, |
| 13009 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13010 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13011 | {__LINE__, |
| 13012 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13013 | AUTH_NONE, |
| 13014 | OK, |
| 13015 | kSecureServer, |
| 13016 | AUTH_ASYNC, |
| 13017 | OK, |
| 13018 | 2, |
| 13019 | 0, |
| 13020 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13021 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13022 | {__LINE__, |
| 13023 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13024 | AUTH_NONE, |
| 13025 | OK, |
| 13026 | kSecureServer, |
| 13027 | AUTH_ASYNC, |
| 13028 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13029 | 2, |
| 13030 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13031 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13032 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13033 | {__LINE__, |
| 13034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13035 | AUTH_NONE, |
| 13036 | OK, |
| 13037 | kSecureServer, |
| 13038 | AUTH_NONE, |
| 13039 | OK, |
| 13040 | 1, |
| 13041 | 0, |
| 13042 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13043 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13044 | {__LINE__, |
| 13045 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13046 | AUTH_NONE, |
| 13047 | OK, |
| 13048 | kSecureServer, |
| 13049 | AUTH_SYNC, |
| 13050 | OK, |
| 13051 | 2, |
| 13052 | 0, |
| 13053 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13054 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13055 | {__LINE__, |
| 13056 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13057 | AUTH_NONE, |
| 13058 | OK, |
| 13059 | kSecureServer, |
| 13060 | AUTH_SYNC, |
| 13061 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13062 | 2, |
| 13063 | 0, |
| 13064 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13065 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13066 | {__LINE__, |
| 13067 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13068 | AUTH_NONE, |
| 13069 | OK, |
| 13070 | kSecureServer, |
| 13071 | AUTH_ASYNC, |
| 13072 | OK, |
| 13073 | 2, |
| 13074 | 0, |
| 13075 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13076 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13077 | {__LINE__, |
| 13078 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13079 | AUTH_NONE, |
| 13080 | OK, |
| 13081 | kSecureServer, |
| 13082 | AUTH_ASYNC, |
| 13083 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13084 | 2, |
| 13085 | 0, |
| 13086 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13087 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13088 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13089 | {__LINE__, |
| 13090 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13091 | AUTH_SYNC, |
| 13092 | OK, |
| 13093 | kSecureServer, |
| 13094 | AUTH_NONE, |
| 13095 | OK, |
| 13096 | 2, |
| 13097 | 1, |
| 13098 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13099 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13100 | {__LINE__, |
| 13101 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13102 | AUTH_SYNC, |
| 13103 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13104 | kSecureServer, |
| 13105 | AUTH_NONE, |
| 13106 | OK, |
| 13107 | 2, |
| 13108 | kNoSSL, |
| 13109 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13110 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13111 | {__LINE__, |
| 13112 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13113 | AUTH_SYNC, |
| 13114 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13115 | kSecureServer, |
| 13116 | AUTH_NONE, |
| 13117 | OK, |
| 13118 | 2, |
| 13119 | kNoSSL, |
| 13120 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13121 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13122 | {__LINE__, |
| 13123 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13124 | AUTH_SYNC, |
| 13125 | ERR_UNEXPECTED, |
| 13126 | kSecureServer, |
| 13127 | AUTH_NONE, |
| 13128 | OK, |
| 13129 | 2, |
| 13130 | kNoSSL, |
| 13131 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13132 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13133 | {__LINE__, |
| 13134 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13135 | AUTH_ASYNC, |
| 13136 | OK, |
| 13137 | kSecureServer, |
| 13138 | AUTH_NONE, |
| 13139 | OK, |
| 13140 | 2, |
| 13141 | 1, |
| 13142 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13143 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13144 | {__LINE__, |
| 13145 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13146 | AUTH_ASYNC, |
| 13147 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13148 | kSecureServer, |
| 13149 | AUTH_NONE, |
| 13150 | OK, |
| 13151 | 2, |
| 13152 | kNoSSL, |
| 13153 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13154 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13155 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13156 | {__LINE__, |
| 13157 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13158 | AUTH_SYNC, |
| 13159 | OK, |
| 13160 | kSecureServer, |
| 13161 | AUTH_SYNC, |
| 13162 | OK, |
| 13163 | 3, |
| 13164 | 1, |
| 13165 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13166 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13167 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13168 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13169 | {__LINE__, |
| 13170 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13171 | AUTH_SYNC, |
| 13172 | OK, |
| 13173 | kSecureServer, |
| 13174 | AUTH_SYNC, |
| 13175 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13176 | 3, |
| 13177 | 1, |
| 13178 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13179 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13180 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13181 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13182 | {__LINE__, |
| 13183 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13184 | AUTH_ASYNC, |
| 13185 | OK, |
| 13186 | kSecureServer, |
| 13187 | AUTH_SYNC, |
| 13188 | OK, |
| 13189 | 3, |
| 13190 | 1, |
| 13191 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13192 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13193 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13194 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13195 | {__LINE__, |
| 13196 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13197 | AUTH_ASYNC, |
| 13198 | OK, |
| 13199 | kSecureServer, |
| 13200 | AUTH_SYNC, |
| 13201 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13202 | 3, |
| 13203 | 1, |
| 13204 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13205 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13206 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13207 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13208 | {__LINE__, |
| 13209 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13210 | AUTH_SYNC, |
| 13211 | OK, |
| 13212 | kSecureServer, |
| 13213 | AUTH_ASYNC, |
| 13214 | OK, |
| 13215 | 3, |
| 13216 | 1, |
| 13217 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13218 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13219 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13220 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13221 | {__LINE__, |
| 13222 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13223 | AUTH_SYNC, |
| 13224 | OK, |
| 13225 | kSecureServer, |
| 13226 | AUTH_ASYNC, |
| 13227 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13228 | 3, |
| 13229 | 1, |
| 13230 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13231 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13232 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13233 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13234 | {__LINE__, |
| 13235 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13236 | AUTH_ASYNC, |
| 13237 | OK, |
| 13238 | kSecureServer, |
| 13239 | AUTH_ASYNC, |
| 13240 | OK, |
| 13241 | 3, |
| 13242 | 1, |
| 13243 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13244 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13245 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13246 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13247 | {__LINE__, |
| 13248 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13249 | AUTH_ASYNC, |
| 13250 | OK, |
| 13251 | kSecureServer, |
| 13252 | AUTH_ASYNC, |
| 13253 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13254 | 3, |
| 13255 | 1, |
| 13256 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13257 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13258 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13259 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13260 | {__LINE__, |
| 13261 | kProxy, |
| 13262 | AUTH_ASYNC, |
| 13263 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13264 | kSecureServer, |
| 13265 | AUTH_ASYNC, |
| 13266 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13267 | 4, |
| 13268 | 2, |
| 13269 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13270 | TestRound(kConnect, kProxyChallenge, OK), |
| 13271 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13272 | &kServerChallenge), |
| 13273 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13274 | }; |
| 13275 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13276 | for (const auto& test_config : test_configs) { |
| 13277 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13278 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13279 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13280 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13281 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13282 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13283 | |
| 13284 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13285 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13286 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13287 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13288 | std::string auth_challenge = "Mock realm=proxy"; |
| 13289 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13290 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13291 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13292 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13293 | empty_ssl_info, origin, |
| 13294 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13295 | auth_handler->SetGenerateExpectation( |
| 13296 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13297 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13298 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13299 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13300 | } |
| 13301 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13302 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13303 | std::string auth_challenge = "Mock realm=server"; |
| 13304 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13305 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13306 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13307 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13308 | empty_ssl_info, origin, |
| 13309 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13310 | auth_handler->SetGenerateExpectation( |
| 13311 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13312 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13313 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13314 | |
| 13315 | // The second handler always succeeds. It should only be used where there |
| 13316 | // are multiple auth sessions for server auth in the same network |
| 13317 | // transaction using the same auth scheme. |
| 13318 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13319 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13320 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13321 | empty_ssl_info, origin, |
| 13322 | NetLogWithSource()); |
| 13323 | second_handler->SetGenerateExpectation(true, OK); |
| 13324 | auth_factory->AddMockHandler(second_handler.release(), |
| 13325 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13326 | } |
| 13327 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13328 | session_deps_.proxy_resolution_service = |
| 13329 | ProxyResolutionService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13330 | } else { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13331 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13332 | } |
| 13333 | |
| 13334 | HttpRequestInfo request; |
| 13335 | request.method = "GET"; |
| 13336 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13337 | request.traffic_annotation = |
| 13338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13339 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13341 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13342 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13343 | |
| 13344 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13345 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13346 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13347 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13348 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13349 | |
| 13350 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13351 | mock_reads.back().push_back(read_write_round.read); |
| 13352 | mock_writes.back().push_back(read_write_round.write); |
| 13353 | |
| 13354 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13355 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13356 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13357 | mock_reads.push_back(std::vector<MockRead>()); |
| 13358 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13359 | } |
| 13360 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13361 | if (read_write_round.extra_read) { |
| 13362 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13363 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13364 | if (read_write_round.extra_write) { |
| 13365 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13366 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13367 | |
| 13368 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13369 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13370 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13371 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13372 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13373 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13374 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13375 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13376 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13377 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13378 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13379 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13380 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13381 | } |
| 13382 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13383 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13384 | // they are as well. |
| 13385 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13386 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13387 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13388 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13389 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13390 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13391 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13392 | int rv; |
| 13393 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13394 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13395 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13396 | rv = trans.RestartWithAuth( |
| 13397 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13398 | } |
| 13399 | if (rv == ERR_IO_PENDING) |
| 13400 | rv = callback.WaitForResult(); |
| 13401 | |
| 13402 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13403 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13404 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13405 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13406 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13407 | continue; |
| 13408 | } |
| 13409 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13410 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13411 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13412 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13413 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13414 | } |
| 13415 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13416 | } |
| 13417 | } |
| 13418 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13419 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13420 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13421 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13422 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13423 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13424 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13425 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13426 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13427 | |
| 13428 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13429 | auth_handler->set_connection_based(true); |
| 13430 | std::string auth_challenge = "Mock realm=server"; |
| 13431 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13432 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13433 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13434 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13435 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13436 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13437 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13438 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13439 | int rv = OK; |
| 13440 | const HttpResponseInfo* response = NULL; |
| 13441 | HttpRequestInfo request; |
| 13442 | request.method = "GET"; |
| 13443 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13444 | request.traffic_annotation = |
| 13445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13446 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13448 | |
| 13449 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13450 | // to validate that the TCP socket is not released to the pool between |
| 13451 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13452 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13453 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13454 | 50, // Max sockets for pool |
| 13455 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13456 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13457 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13458 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13459 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13460 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13463 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13464 | |
| 13465 | const MockWrite kGet( |
| 13466 | "GET / HTTP/1.1\r\n" |
| 13467 | "Host: www.example.com\r\n" |
| 13468 | "Connection: keep-alive\r\n\r\n"); |
| 13469 | const MockWrite kGetAuth( |
| 13470 | "GET / HTTP/1.1\r\n" |
| 13471 | "Host: www.example.com\r\n" |
| 13472 | "Connection: keep-alive\r\n" |
| 13473 | "Authorization: auth_token\r\n\r\n"); |
| 13474 | |
| 13475 | const MockRead kServerChallenge( |
| 13476 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13477 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13478 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13479 | "Content-Length: 14\r\n\r\n" |
| 13480 | "Unauthorized\r\n"); |
| 13481 | const MockRead kSuccess( |
| 13482 | "HTTP/1.1 200 OK\r\n" |
| 13483 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13484 | "Content-Length: 3\r\n\r\n" |
| 13485 | "Yes"); |
| 13486 | |
| 13487 | MockWrite writes[] = { |
| 13488 | // First round |
| 13489 | kGet, |
| 13490 | // Second round |
| 13491 | kGetAuth, |
| 13492 | // Third round |
| 13493 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13494 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13495 | kGetAuth, |
| 13496 | // Competing request |
| 13497 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13498 | }; |
| 13499 | MockRead reads[] = { |
| 13500 | // First round |
| 13501 | kServerChallenge, |
| 13502 | // Second round |
| 13503 | kServerChallenge, |
| 13504 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13505 | kServerChallenge, |
| 13506 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13507 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13508 | // Competing response |
| 13509 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13510 | }; |
| 13511 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13512 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13513 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13514 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13515 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13516 | |
| 13517 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13518 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13519 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13520 | if (rv == ERR_IO_PENDING) |
| 13521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13522 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13523 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13524 | ASSERT_TRUE(response); |
| 13525 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13526 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13527 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13528 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13529 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13530 | // In between rounds, another request comes in for the same domain. |
| 13531 | // It should not be able to grab the TCP socket that trans has already |
| 13532 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13533 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13534 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13535 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13536 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13538 | // callback_compete.WaitForResult at this point would stall forever, |
| 13539 | // since the HttpNetworkTransaction does not release the request back to |
| 13540 | // the pool until after authentication completes. |
| 13541 | |
| 13542 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13543 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13544 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13545 | if (rv == ERR_IO_PENDING) |
| 13546 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13547 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13548 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13549 | ASSERT_TRUE(response); |
| 13550 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13551 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13552 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13553 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13554 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13555 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13556 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13557 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13558 | if (rv == ERR_IO_PENDING) |
| 13559 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13560 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13561 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13562 | ASSERT_TRUE(response); |
| 13563 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13564 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13565 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13566 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13567 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13568 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13569 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13570 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13571 | if (rv == ERR_IO_PENDING) |
| 13572 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13573 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13574 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13575 | ASSERT_TRUE(response); |
| 13576 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13577 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13578 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13579 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13580 | // auth handler should transition to a DONE state in concert with the remote |
| 13581 | // server. But that's not something we can test here with a mock handler. |
| 13582 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13583 | auth_handler->state()); |
| 13584 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13585 | // Read the body since the fourth round was successful. This will also |
| 13586 | // release the socket back to the pool. |
| 13587 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13588 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13589 | if (rv == ERR_IO_PENDING) |
| 13590 | rv = callback.WaitForResult(); |
| 13591 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13592 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13593 | EXPECT_EQ(0, rv); |
| 13594 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13595 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13596 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13597 | |
| 13598 | // The competing request can now finish. Wait for the headers and then |
| 13599 | // read the body. |
| 13600 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13601 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13602 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13603 | if (rv == ERR_IO_PENDING) |
| 13604 | rv = callback.WaitForResult(); |
| 13605 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13606 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13607 | EXPECT_EQ(0, rv); |
| 13608 | |
| 13609 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13610 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13611 | } |
| 13612 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13613 | // This tests the case that a request is issued via http instead of spdy after |
| 13614 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13615 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13616 | HttpRequestInfo request; |
| 13617 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13618 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13619 | request.traffic_annotation = |
| 13620 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13621 | |
| 13622 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13623 | MockWrite( |
| 13624 | "GET / HTTP/1.1\r\n" |
| 13625 | "Host: www.example.org\r\n" |
| 13626 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13627 | }; |
| 13628 | |
| 13629 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13630 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13631 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13632 | MockRead("\r\n"), |
| 13633 | MockRead("hello world"), |
| 13634 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13635 | }; |
| 13636 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13637 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13638 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13639 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13640 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13641 | |
| 13642 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13643 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13646 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13651 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13652 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13654 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13656 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13657 | ASSERT_TRUE(response); |
| 13658 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13659 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13660 | |
| 13661 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13662 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13663 | EXPECT_EQ("hello world", response_data); |
| 13664 | |
| 13665 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13666 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13667 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13668 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13669 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13670 | // immediate server closing of the socket. |
| 13671 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13672 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13673 | HttpRequestInfo request; |
| 13674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13675 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13676 | request.traffic_annotation = |
| 13677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13678 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13679 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13680 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13682 | |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 13683 | SpdySerializedFrame req(spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13684 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13685 | |
| 13686 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13687 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13688 | }; |
| 13689 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13690 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13691 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13692 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13694 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13701 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13702 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13703 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13704 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13705 | // it gets it. This is needed since the auth handler may get destroyed |
| 13706 | // before we get a chance to query it. |
| 13707 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13708 | public: |
| 13709 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13710 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13711 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13712 | |
| 13713 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13714 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13715 | const HttpRequestInfo* request, |
| 13716 | const CompletionCallback& callback, |
| 13717 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13718 | *url_ = request->url; |
| 13719 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13720 | credentials, request, callback, auth_token); |
| 13721 | } |
| 13722 | |
| 13723 | private: |
| 13724 | GURL* url_; |
| 13725 | }; |
| 13726 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13727 | // Test that if we cancel the transaction as the connection is completing, that |
| 13728 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13729 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13730 | // Setup everything about the connection to complete synchronously, so that |
| 13731 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13732 | // for is the callback from the HttpStreamRequest. |
| 13733 | // Then cancel the transaction. |
| 13734 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13735 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13736 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13737 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13738 | MockRead(SYNCHRONOUS, "hello world"), |
| 13739 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13740 | }; |
| 13741 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13742 | HttpRequestInfo request; |
| 13743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13744 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13745 | request.traffic_annotation = |
| 13746 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13747 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13748 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13749 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13750 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13751 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13752 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13753 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13754 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13755 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13757 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13758 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13759 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13760 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13762 | trans.reset(); // Cancel the transaction here. |
| 13763 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13764 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13765 | } |
| 13766 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13767 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13768 | // stream is drained properly and added back to the socket pool. The main |
| 13769 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13770 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13771 | // deleted. |
| 13772 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13773 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13774 | MockRead data_reads[] = { |
| 13775 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13776 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13777 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13778 | MockRead(ASYNC, "1"), |
| 13779 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13780 | // HttpNetworkTransaction has been deleted. |
| 13781 | MockRead(ASYNC, "2"), |
| 13782 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13783 | }; |
| 13784 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13786 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13787 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13788 | |
| 13789 | { |
| 13790 | HttpRequestInfo request; |
| 13791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13792 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13793 | request.traffic_annotation = |
| 13794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13795 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13797 | TestCompletionCallback callback; |
| 13798 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13799 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13800 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13801 | callback.WaitForResult(); |
| 13802 | |
| 13803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13804 | ASSERT_TRUE(response); |
| 13805 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13806 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13807 | |
| 13808 | // The transaction and HttpRequestInfo are deleted. |
| 13809 | } |
| 13810 | |
| 13811 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13812 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13813 | |
| 13814 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13815 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13816 | } |
| 13817 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13818 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13819 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13820 | session_deps_.proxy_resolution_service = |
| 13821 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13822 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13823 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13824 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13825 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13826 | HttpRequestInfo request; |
| 13827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13828 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13829 | request.traffic_annotation = |
| 13830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13831 | |
| 13832 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13833 | MockWrite( |
| 13834 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13835 | "Host: www.example.org\r\n" |
| 13836 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13837 | }; |
| 13838 | |
| 13839 | MockRead data_reads1[] = { |
| 13840 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13841 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13842 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13843 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13844 | }; |
| 13845 | |
| 13846 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13847 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13848 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13850 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13853 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13854 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13855 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13856 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13857 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13858 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13859 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13860 | |
| 13861 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13862 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13865 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13866 | |
| 13867 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13868 | EXPECT_EQ(200, response->headers->response_code()); |
| 13869 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13870 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13871 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13872 | HostPortPair::FromString("myproxy:70")), |
| 13873 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13874 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13875 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13876 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13877 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13878 | |
| 13879 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13880 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13881 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13882 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13883 | } |
| 13884 | |
| 13885 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13886 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13887 | session_deps_.proxy_resolution_service = |
| 13888 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13889 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13890 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13892 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13893 | HttpRequestInfo request; |
| 13894 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13895 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13896 | request.traffic_annotation = |
| 13897 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13898 | |
| 13899 | // Since we have proxy, should try to establish tunnel. |
| 13900 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13901 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13902 | "Host: www.example.org:443\r\n" |
| 13903 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13904 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13905 | MockWrite("GET / HTTP/1.1\r\n" |
| 13906 | "Host: www.example.org\r\n" |
| 13907 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13908 | }; |
| 13909 | |
| 13910 | MockRead data_reads1[] = { |
| 13911 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13912 | |
| 13913 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13915 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13917 | }; |
| 13918 | |
| 13919 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13920 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13921 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13922 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13925 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13927 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13928 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13929 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13930 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13931 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13933 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13935 | |
| 13936 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13937 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13938 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13939 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13940 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13941 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13942 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13943 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13944 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13945 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13946 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13948 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13949 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13950 | |
| 13951 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13952 | EXPECT_EQ(200, response->headers->response_code()); |
| 13953 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13954 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13955 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13956 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13957 | HostPortPair::FromString("myproxy:70")), |
| 13958 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13959 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13960 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13961 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13962 | |
| 13963 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13964 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13965 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13966 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13967 | } |
| 13968 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13969 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13970 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13971 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13972 | session_deps_.proxy_resolution_service = |
| 13973 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13974 | BoundTestNetLog log; |
| 13975 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13977 | |
| 13978 | HttpRequestInfo request; |
| 13979 | request.method = "GET"; |
| 13980 | request.url = GURL("https://[::1]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13981 | request.traffic_annotation = |
| 13982 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13983 | |
| 13984 | // Since we have proxy, should try to establish tunnel. |
| 13985 | MockWrite data_writes1[] = { |
| 13986 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13987 | "Host: [::1]:443\r\n" |
| 13988 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13989 | |
| 13990 | MockWrite("GET / HTTP/1.1\r\n" |
| 13991 | "Host: [::1]\r\n" |
| 13992 | "Connection: keep-alive\r\n\r\n"), |
| 13993 | }; |
| 13994 | |
| 13995 | MockRead data_reads1[] = { |
| 13996 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13997 | |
| 13998 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13999 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14000 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14001 | MockRead(SYNCHRONOUS, OK), |
| 14002 | }; |
| 14003 | |
| 14004 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14005 | data_writes1, arraysize(data_writes1)); |
| 14006 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14007 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14009 | |
| 14010 | TestCompletionCallback callback1; |
| 14011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14012 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14014 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14016 | |
| 14017 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14018 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14019 | TestNetLogEntry::List entries; |
| 14020 | log.GetEntries(&entries); |
| 14021 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14022 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14023 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14024 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14025 | entries, pos, |
| 14026 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14027 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14029 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14030 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14031 | |
| 14032 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14033 | EXPECT_EQ(200, response->headers->response_code()); |
| 14034 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14035 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14036 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14037 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14038 | HostPortPair::FromString("myproxy:70")), |
| 14039 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14040 | |
| 14041 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14042 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14043 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14044 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14045 | } |
| 14046 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14047 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14048 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14049 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14050 | session_deps_.proxy_resolution_service = |
| 14051 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14052 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14053 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14055 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14056 | HttpRequestInfo request; |
| 14057 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14058 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14059 | request.traffic_annotation = |
| 14060 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14061 | |
| 14062 | // Since we have proxy, should try to establish tunnel. |
| 14063 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14064 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14065 | "Host: www.example.org:443\r\n" |
| 14066 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14067 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14068 | MockWrite("GET / HTTP/1.1\r\n" |
| 14069 | "Host: www.example.org\r\n" |
| 14070 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14071 | }; |
| 14072 | |
| 14073 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14074 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14075 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14076 | }; |
| 14077 | |
| 14078 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 14079 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14080 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14081 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14082 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14084 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14085 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14088 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14090 | |
| 14091 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14092 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14093 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14094 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14095 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14096 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14097 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14098 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14099 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14100 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14101 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14102 | } |
| 14103 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14104 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14105 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14106 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14107 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14108 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14109 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14110 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14111 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14112 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14113 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14114 | }; |
| 14115 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14116 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 14117 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14118 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14119 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14120 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14121 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14125 | |
| 14126 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14127 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14128 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14129 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14130 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14131 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14132 | |
| 14133 | HttpRequestInfo request; |
| 14134 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14135 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14136 | request.traffic_annotation = |
| 14137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14138 | |
| 14139 | // This is the important line that marks this as a preconnect. |
| 14140 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 14141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14143 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14144 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14145 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14147 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14148 | } |
| 14149 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14150 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14151 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14152 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14153 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14154 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14155 | request_info.url = GURL("https://www.example.com/"); |
| 14156 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14157 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14158 | request_info.traffic_annotation = |
| 14159 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14160 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14161 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14162 | MockWrite data_writes[] = { |
| 14163 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14164 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14165 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14166 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14168 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14170 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14172 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14173 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14174 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14175 | rv = callback.WaitForResult(); |
| 14176 | ASSERT_EQ(error, rv); |
| 14177 | } |
| 14178 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14179 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14180 | // Just check a grab bag of cert errors. |
| 14181 | static const int kErrors[] = { |
| 14182 | ERR_CERT_COMMON_NAME_INVALID, |
| 14183 | ERR_CERT_AUTHORITY_INVALID, |
| 14184 | ERR_CERT_DATE_INVALID, |
| 14185 | }; |
| 14186 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14187 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14188 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14189 | } |
| 14190 | } |
| 14191 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14192 | // Ensure that a client certificate is removed from the SSL client auth |
| 14193 | // cache when: |
| 14194 | // 1) No proxy is involved. |
| 14195 | // 2) TLS False Start is disabled. |
| 14196 | // 3) The initial TLS handshake requests a client certificate. |
| 14197 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14198 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14199 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14200 | request_info.url = GURL("https://www.example.com/"); |
| 14201 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14202 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14203 | request_info.traffic_annotation = |
| 14204 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14205 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14206 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14207 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14208 | |
| 14209 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14210 | // CertificateRequest is received for the first time, the handshake will |
| 14211 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14212 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14213 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14215 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14216 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14217 | |
| 14218 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14219 | // False Start is not being used, the result of the SSL handshake will be |
| 14220 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14221 | // matches the result of a server sending a handshake_failure alert, |
| 14222 | // rather than a Finished message, because it requires a client |
| 14223 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14224 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14225 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14227 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14228 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14229 | |
| 14230 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14231 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14232 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14233 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14234 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14235 | // requiring a client certificate, this fallback handshake should also |
| 14236 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14237 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14238 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14239 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14240 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14241 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14242 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14243 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14244 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14245 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14246 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14247 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14248 | // requiring a client certificate, this fallback handshake should also |
| 14249 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14250 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14251 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14252 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14253 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14254 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14255 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14257 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14258 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14259 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14260 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14261 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14262 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14263 | |
| 14264 | // Complete the SSL handshake, which should abort due to requiring a |
| 14265 | // client certificate. |
| 14266 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14267 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14268 | |
| 14269 | // Indicate that no certificate should be supplied. From the perspective |
| 14270 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14271 | // certificate, so this is the same as supply a |
| 14272 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14273 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14274 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14275 | |
| 14276 | // Ensure the certificate was added to the client auth cache before |
| 14277 | // allowing the connection to continue restarting. |
| 14278 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14279 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14280 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14281 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14282 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14283 | |
| 14284 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14285 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14286 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14288 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14289 | |
| 14290 | // Ensure that the client certificate is removed from the cache on a |
| 14291 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14292 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14293 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14294 | } |
| 14295 | |
| 14296 | // Ensure that a client certificate is removed from the SSL client auth |
| 14297 | // cache when: |
| 14298 | // 1) No proxy is involved. |
| 14299 | // 2) TLS False Start is enabled. |
| 14300 | // 3) The initial TLS handshake requests a client certificate. |
| 14301 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14302 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14303 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14304 | request_info.url = GURL("https://www.example.com/"); |
| 14305 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14306 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14307 | request_info.traffic_annotation = |
| 14308 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14309 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14310 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14311 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14312 | |
| 14313 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14314 | // return successfully after reading up to the peer's Certificate message. |
| 14315 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14316 | // enqueue application data to be sent in the same packet as the |
| 14317 | // ChangeCipherSpec and Finished messages. |
| 14318 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14319 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14320 | // Finished messages. If there was an error negotiating with the peer, |
| 14321 | // such as due to the peer requiring a client certificate when none was |
| 14322 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14323 | // called. |
| 14324 | |
| 14325 | // Like the non-False Start case, when a client certificate is requested by |
| 14326 | // the peer, the handshake is aborted during the Connect() call. |
| 14327 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14328 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14329 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14331 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14332 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14333 | |
| 14334 | // When a client certificate is supplied, Connect() will not be aborted |
| 14335 | // when the peer requests the certificate. Instead, the handshake will |
| 14336 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14337 | // the socket. The handshake messages are not processed until Read() is |
| 14338 | // called, which then detects that the handshake was aborted, due to the |
| 14339 | // peer sending a handshake_failure because it requires a client |
| 14340 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14341 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14342 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14343 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14344 | MockRead data2_reads[] = { |
| 14345 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14346 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14347 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14348 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14349 | |
| 14350 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14351 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14352 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14353 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14354 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14355 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14356 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14357 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14358 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14359 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14360 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14361 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14362 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14363 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14364 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14365 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14366 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14367 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14368 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14369 | ssl_data5.cert_request_info = cert_request.get(); |
| 14370 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14371 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14372 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14373 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14376 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14377 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14378 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14379 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14380 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14381 | |
| 14382 | // Complete the SSL handshake, which should abort due to requiring a |
| 14383 | // client certificate. |
| 14384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14385 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14386 | |
| 14387 | // Indicate that no certificate should be supplied. From the perspective |
| 14388 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14389 | // certificate, so this is the same as supply a |
| 14390 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14391 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14392 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14393 | |
| 14394 | // Ensure the certificate was added to the client auth cache before |
| 14395 | // allowing the connection to continue restarting. |
| 14396 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14397 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14398 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14399 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14400 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14401 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14402 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14403 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14404 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14405 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14406 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14407 | |
| 14408 | // Ensure that the client certificate is removed from the cache on a |
| 14409 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14410 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14411 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14412 | } |
| 14413 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14414 | // Ensure that a client certificate is removed from the SSL client auth |
| 14415 | // cache when: |
| 14416 | // 1) An HTTPS proxy is involved. |
| 14417 | // 3) The HTTPS proxy requests a client certificate. |
| 14418 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14419 | // proxy. |
| 14420 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14421 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14422 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14423 | session_deps_.proxy_resolution_service = |
| 14424 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14425 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14426 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14427 | |
| 14428 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14429 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14430 | |
| 14431 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14432 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14433 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14434 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14435 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14436 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14437 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14438 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14439 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14440 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14441 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14442 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14443 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14444 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14445 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14446 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14447 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14448 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14449 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14450 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14451 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14452 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14453 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14454 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14455 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14456 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14457 | requests[0].url = GURL("https://www.example.com/"); |
| 14458 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14459 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14460 | requests[0].traffic_annotation = |
| 14461 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14462 | |
| 14463 | requests[1].url = GURL("http://www.example.com/"); |
| 14464 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14465 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14466 | requests[1].traffic_annotation = |
| 14467 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14468 | |
| 14469 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14470 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14473 | |
| 14474 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14475 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14476 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14477 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14478 | |
| 14479 | // Complete the SSL handshake, which should abort due to requiring a |
| 14480 | // client certificate. |
| 14481 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14482 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14483 | |
| 14484 | // Indicate that no certificate should be supplied. From the perspective |
| 14485 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14486 | // certificate, so this is the same as supply a |
| 14487 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14488 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14489 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14490 | |
| 14491 | // Ensure the certificate was added to the client auth cache before |
| 14492 | // allowing the connection to continue restarting. |
| 14493 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14494 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14495 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14496 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14497 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14498 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14499 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14500 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14501 | HostPortPair("www.example.com", 443), &client_cert, |
| 14502 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14503 | |
| 14504 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14505 | // then consume ssl_data3, which should also fail. The result code is |
| 14506 | // checked against what ssl_data3 should return. |
| 14507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14508 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14509 | |
| 14510 | // Now that the new handshake has failed, ensure that the client |
| 14511 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14512 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14513 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14514 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14515 | HostPortPair("www.example.com", 443), &client_cert, |
| 14516 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14517 | } |
| 14518 | } |
| 14519 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14520 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14521 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14522 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14524 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14525 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14526 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14527 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14528 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14529 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14530 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14531 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14532 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14533 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14534 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14535 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14536 | SpdySerializedFrame host1_resp_body( |
| 14537 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14538 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14539 | SpdySerializedFrame host2_resp_body( |
| 14540 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14541 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14542 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14543 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14544 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14545 | }; |
| 14546 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14547 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14548 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14549 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14550 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14551 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14552 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14553 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14554 | HttpRequestInfo request1; |
| 14555 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14556 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14557 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14558 | request1.traffic_annotation = |
| 14559 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14560 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14561 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14562 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14564 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14565 | |
| 14566 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14567 | ASSERT_TRUE(response); |
| 14568 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14569 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14570 | |
| 14571 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14572 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14573 | EXPECT_EQ("hello!", response_data); |
| 14574 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14575 | // Preload mail.example.com into HostCache. |
| 14576 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14577 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14578 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14579 | std::unique_ptr<HostResolver::Request> request; |
| 14580 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14581 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14582 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14584 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14585 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14586 | |
| 14587 | HttpRequestInfo request2; |
| 14588 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14589 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14590 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14591 | request2.traffic_annotation = |
| 14592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14593 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14595 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14597 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14598 | |
| 14599 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14600 | ASSERT_TRUE(response); |
| 14601 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14602 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14603 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14604 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14605 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14606 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14607 | } |
| 14608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14609 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14610 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14611 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14613 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14614 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14615 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14616 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14617 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14618 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14619 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14620 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14621 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14622 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14623 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14624 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | SpdySerializedFrame host1_resp_body( |
| 14626 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14627 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14628 | SpdySerializedFrame host2_resp_body( |
| 14629 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14630 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14631 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14632 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14633 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14634 | }; |
| 14635 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14636 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14637 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14638 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14639 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14640 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14641 | |
| 14642 | TestCompletionCallback callback; |
| 14643 | HttpRequestInfo request1; |
| 14644 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14645 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14646 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14647 | request1.traffic_annotation = |
| 14648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14649 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14651 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14653 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14654 | |
| 14655 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14656 | ASSERT_TRUE(response); |
| 14657 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14658 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14659 | |
| 14660 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14661 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14662 | EXPECT_EQ("hello!", response_data); |
| 14663 | |
| 14664 | HttpRequestInfo request2; |
| 14665 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14666 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14667 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14668 | request2.traffic_annotation = |
| 14669 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14670 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14671 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14672 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14674 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14675 | |
| 14676 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14677 | ASSERT_TRUE(response); |
| 14678 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14679 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14680 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14681 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14682 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14683 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14684 | } |
| 14685 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14686 | // Regression test for https://crbug.com/546991. |
| 14687 | // The server might not be able to serve an IP pooled request, and might send a |
| 14688 | // 421 Misdirected Request response status to indicate this. |
| 14689 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14690 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14691 | // Two hosts resolve to the same IP address. |
| 14692 | const std::string ip_addr = "1.2.3.4"; |
| 14693 | IPAddress ip; |
| 14694 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14695 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14696 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14697 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14698 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14699 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14700 | |
| 14701 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14702 | |
| 14703 | // Two requests on the first connection. |
| 14704 | SpdySerializedFrame req1( |
| 14705 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14706 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14707 | SpdySerializedFrame req2( |
| 14708 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14709 | SpdySerializedFrame rst( |
| 14710 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14711 | MockWrite writes1[] = { |
| 14712 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14713 | CreateMockWrite(rst, 6), |
| 14714 | }; |
| 14715 | |
| 14716 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14717 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14718 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14719 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14720 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14721 | SpdySerializedFrame resp2( |
| 14722 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14723 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14724 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14725 | |
| 14726 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14727 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14728 | arraysize(writes1)); |
| 14729 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14730 | |
| 14731 | AddSSLSocketData(); |
| 14732 | |
| 14733 | // Retry the second request on a second connection. |
| 14734 | SpdyTestUtil spdy_util2; |
| 14735 | SpdySerializedFrame req3( |
| 14736 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14737 | MockWrite writes2[] = { |
| 14738 | CreateMockWrite(req3, 0), |
| 14739 | }; |
| 14740 | |
| 14741 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14742 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14743 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14744 | MockRead(ASYNC, 0, 3)}; |
| 14745 | |
| 14746 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14747 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14748 | arraysize(writes2)); |
| 14749 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14750 | |
| 14751 | AddSSLSocketData(); |
| 14752 | |
| 14753 | // Preload mail.example.org into HostCache. |
| 14754 | HostPortPair host_port("mail.example.org", 443); |
| 14755 | HostResolver::RequestInfo resolve_info(host_port); |
| 14756 | AddressList ignored; |
| 14757 | std::unique_ptr<HostResolver::Request> request; |
| 14758 | TestCompletionCallback callback; |
| 14759 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14760 | &ignored, callback.callback(), |
| 14761 | &request, NetLogWithSource()); |
| 14762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14763 | rv = callback.WaitForResult(); |
| 14764 | EXPECT_THAT(rv, IsOk()); |
| 14765 | |
| 14766 | HttpRequestInfo request1; |
| 14767 | request1.method = "GET"; |
| 14768 | request1.url = GURL("https://www.example.org/"); |
| 14769 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14770 | request1.traffic_annotation = |
| 14771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14772 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14773 | |
| 14774 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14775 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14776 | rv = callback.WaitForResult(); |
| 14777 | EXPECT_THAT(rv, IsOk()); |
| 14778 | |
| 14779 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14780 | ASSERT_TRUE(response); |
| 14781 | ASSERT_TRUE(response->headers); |
| 14782 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14783 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14784 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14785 | std::string response_data; |
| 14786 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14787 | EXPECT_EQ("hello!", response_data); |
| 14788 | |
| 14789 | HttpRequestInfo request2; |
| 14790 | request2.method = "GET"; |
| 14791 | request2.url = GURL("https://mail.example.org/"); |
| 14792 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14793 | request2.traffic_annotation = |
| 14794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14795 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14796 | |
| 14797 | BoundTestNetLog log; |
| 14798 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14800 | rv = callback.WaitForResult(); |
| 14801 | EXPECT_THAT(rv, IsOk()); |
| 14802 | |
| 14803 | response = trans2.GetResponseInfo(); |
| 14804 | ASSERT_TRUE(response); |
| 14805 | ASSERT_TRUE(response->headers); |
| 14806 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14807 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14808 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14809 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14810 | EXPECT_EQ("hello!", response_data); |
| 14811 | |
| 14812 | TestNetLogEntry::List entries; |
| 14813 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14814 | ExpectLogContainsSomewhere( |
| 14815 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14816 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14817 | } |
| 14818 | |
| 14819 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14820 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14821 | // portions of the response. |
| 14822 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14823 | // Two hosts resolve to the same IP address. |
| 14824 | const std::string ip_addr = "1.2.3.4"; |
| 14825 | IPAddress ip; |
| 14826 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14827 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14828 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14829 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14830 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14831 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14832 | |
| 14833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14834 | |
| 14835 | // Two requests on the first connection. |
| 14836 | SpdySerializedFrame req1( |
| 14837 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14838 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14839 | SpdySerializedFrame req2( |
| 14840 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14841 | SpdySerializedFrame rst( |
| 14842 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14843 | MockWrite writes1[] = { |
| 14844 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14845 | CreateMockWrite(rst, 6), |
| 14846 | }; |
| 14847 | |
| 14848 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14849 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14850 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14851 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14852 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14853 | SpdySerializedFrame resp2( |
| 14854 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14855 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14856 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14857 | |
| 14858 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14859 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14860 | arraysize(writes1)); |
| 14861 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14862 | |
| 14863 | AddSSLSocketData(); |
| 14864 | |
| 14865 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14866 | // Retry again. |
| 14867 | SpdyTestUtil spdy_util2; |
| 14868 | SpdySerializedFrame req3( |
| 14869 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14870 | MockWrite writes2[] = { |
| 14871 | CreateMockWrite(req3, 0), |
| 14872 | }; |
| 14873 | |
| 14874 | SpdySerializedFrame resp3( |
| 14875 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14876 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14877 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14878 | MockRead(ASYNC, 0, 3)}; |
| 14879 | |
| 14880 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14881 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14882 | arraysize(writes2)); |
| 14883 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14884 | |
| 14885 | AddSSLSocketData(); |
| 14886 | |
| 14887 | // Preload mail.example.org into HostCache. |
| 14888 | HostPortPair host_port("mail.example.org", 443); |
| 14889 | HostResolver::RequestInfo resolve_info(host_port); |
| 14890 | AddressList ignored; |
| 14891 | std::unique_ptr<HostResolver::Request> request; |
| 14892 | TestCompletionCallback callback; |
| 14893 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14894 | &ignored, callback.callback(), |
| 14895 | &request, NetLogWithSource()); |
| 14896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14897 | rv = callback.WaitForResult(); |
| 14898 | EXPECT_THAT(rv, IsOk()); |
| 14899 | |
| 14900 | HttpRequestInfo request1; |
| 14901 | request1.method = "GET"; |
| 14902 | request1.url = GURL("https://www.example.org/"); |
| 14903 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14904 | request1.traffic_annotation = |
| 14905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14906 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14907 | |
| 14908 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14910 | rv = callback.WaitForResult(); |
| 14911 | EXPECT_THAT(rv, IsOk()); |
| 14912 | |
| 14913 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14914 | ASSERT_TRUE(response); |
| 14915 | ASSERT_TRUE(response->headers); |
| 14916 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14917 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14918 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14919 | std::string response_data; |
| 14920 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14921 | EXPECT_EQ("hello!", response_data); |
| 14922 | |
| 14923 | HttpRequestInfo request2; |
| 14924 | request2.method = "GET"; |
| 14925 | request2.url = GURL("https://mail.example.org/"); |
| 14926 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14927 | request2.traffic_annotation = |
| 14928 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14929 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14930 | |
| 14931 | BoundTestNetLog log; |
| 14932 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14934 | rv = callback.WaitForResult(); |
| 14935 | EXPECT_THAT(rv, IsOk()); |
| 14936 | |
| 14937 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14938 | // caller. |
| 14939 | response = trans2.GetResponseInfo(); |
| 14940 | ASSERT_TRUE(response); |
| 14941 | ASSERT_TRUE(response->headers); |
| 14942 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14943 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14944 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14945 | EXPECT_TRUE(response->ssl_info.cert); |
| 14946 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14947 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14948 | } |
| 14949 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14950 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14951 | public: |
| 14952 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14953 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14954 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14955 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14956 | int ResolveFromCache(const RequestInfo& info, |
| 14957 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14958 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14959 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14960 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14961 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14962 | return rv; |
| 14963 | } |
| 14964 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14965 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14966 | const HostPortPair host_port_; |
| 14967 | }; |
| 14968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14969 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14970 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14971 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14972 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14973 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14975 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14976 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14977 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14978 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14979 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14980 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14981 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14982 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14983 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14984 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14985 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14986 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14987 | SpdySerializedFrame host1_resp_body( |
| 14988 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14989 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14990 | SpdySerializedFrame host2_resp_body( |
| 14991 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14992 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14993 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14994 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14995 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14996 | }; |
| 14997 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14998 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14999 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15000 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 15001 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15002 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15003 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15004 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15005 | HttpRequestInfo request1; |
| 15006 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15007 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15008 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15009 | request1.traffic_annotation = |
| 15010 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15011 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15012 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15013 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15015 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15016 | |
| 15017 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15018 | ASSERT_TRUE(response); |
| 15019 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15020 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15021 | |
| 15022 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15023 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15024 | EXPECT_EQ("hello!", response_data); |
| 15025 | |
| 15026 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15027 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15028 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15029 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15030 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15031 | &ignored, callback.callback(), |
| 15032 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15034 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15035 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15036 | |
| 15037 | HttpRequestInfo request2; |
| 15038 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15039 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15040 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15041 | request2.traffic_annotation = |
| 15042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15043 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15045 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15047 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15048 | |
| 15049 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15050 | ASSERT_TRUE(response); |
| 15051 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15052 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15053 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15054 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15055 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15056 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15057 | } |
| 15058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15059 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15060 | const std::string https_url = "https://www.example.org:8080/"; |
| 15061 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15062 | |
| 15063 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15064 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15065 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15066 | |
| 15067 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15068 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15069 | }; |
| 15070 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15071 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15072 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15073 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15074 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15075 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15076 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15077 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15078 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15079 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15080 | |
| 15081 | // HTTP GET for the HTTP URL |
| 15082 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15083 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15084 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15085 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15086 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15087 | }; |
| 15088 | |
| 15089 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15090 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15091 | MockRead(ASYNC, 2, "hello"), |
| 15092 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15093 | }; |
| 15094 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15095 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15096 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15097 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15098 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15099 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15101 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15102 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15103 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15105 | |
| 15106 | // Start the first transaction to set up the SpdySession |
| 15107 | HttpRequestInfo request1; |
| 15108 | request1.method = "GET"; |
| 15109 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15110 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15111 | request1.traffic_annotation = |
| 15112 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15113 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15114 | TestCompletionCallback callback1; |
| 15115 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15116 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15117 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15118 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15119 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15120 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15121 | |
| 15122 | // Now, start the HTTP request |
| 15123 | HttpRequestInfo request2; |
| 15124 | request2.method = "GET"; |
| 15125 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15126 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15127 | request2.traffic_annotation = |
| 15128 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15129 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15130 | TestCompletionCallback callback2; |
| 15131 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15132 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15133 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15134 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15135 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15136 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15137 | } |
| 15138 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15139 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15140 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15141 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15142 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15143 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15144 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15145 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15146 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15147 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15149 | |
| 15150 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15151 | // negotiated. |
| 15152 | StaticSocketDataProvider data; |
| 15153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15154 | |
| 15155 | // 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] | 15156 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15157 | // mocked. This way the request relies on the alternate Job. |
| 15158 | StaticSocketDataProvider data_refused; |
| 15159 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15160 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15161 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15162 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15163 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15164 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15165 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15166 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15167 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15168 | http_server_properties->SetHttp2AlternativeService( |
| 15169 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15170 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15171 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15173 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15174 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15175 | request.traffic_annotation = |
| 15176 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15177 | TestCompletionCallback callback; |
| 15178 | |
| 15179 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15180 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15181 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15182 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15183 | } |
| 15184 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15185 | // 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] | 15186 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15187 | // succeeds, the request should succeed, even if the latter fails because |
| 15188 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15189 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15190 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15191 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15192 | |
| 15193 | // Negotiate HTTP/1.1 with alternative. |
| 15194 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15195 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15197 | |
| 15198 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15199 | // negotiated. |
| 15200 | StaticSocketDataProvider data; |
| 15201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15202 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15203 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15204 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15205 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15206 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15207 | |
| 15208 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15209 | MockWrite("GET / HTTP/1.1\r\n" |
| 15210 | "Host: www.example.org\r\n" |
| 15211 | "Connection: keep-alive\r\n\r\n"), |
| 15212 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15213 | "Host: www.example.org\r\n" |
| 15214 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15215 | }; |
| 15216 | |
| 15217 | MockRead http_reads[] = { |
| 15218 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15219 | MockRead("Content-Type: text/html\r\n"), |
| 15220 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15221 | MockRead("foobar"), |
| 15222 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15223 | MockRead("Content-Type: text/html\r\n"), |
| 15224 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15225 | MockRead("another"), |
| 15226 | }; |
| 15227 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15228 | http_writes, arraysize(http_writes)); |
| 15229 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15230 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15231 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15233 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15234 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15235 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15236 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15237 | http_server_properties->SetHttp2AlternativeService( |
| 15238 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15239 | |
| 15240 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15241 | HttpRequestInfo request1; |
| 15242 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15243 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15244 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15245 | request1.traffic_annotation = |
| 15246 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15247 | TestCompletionCallback callback1; |
| 15248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15249 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15250 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15251 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15252 | |
| 15253 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15254 | ASSERT_TRUE(response1); |
| 15255 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15256 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15257 | |
| 15258 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15259 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15260 | EXPECT_EQ("foobar", response_data1); |
| 15261 | |
| 15262 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15263 | // for alternative service. |
| 15264 | EXPECT_TRUE( |
| 15265 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15266 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15267 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15268 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15269 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15270 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15271 | HttpRequestInfo request2; |
| 15272 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15273 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15274 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15275 | request2.traffic_annotation = |
| 15276 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15277 | TestCompletionCallback callback2; |
| 15278 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15279 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15280 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15281 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15282 | |
| 15283 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15284 | ASSERT_TRUE(response2); |
| 15285 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15286 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15287 | |
| 15288 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15289 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15290 | EXPECT_EQ("another", response_data2); |
| 15291 | } |
| 15292 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15293 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15294 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15295 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15296 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15297 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15298 | HostPortPair alternative("alternative.example.org", 443); |
| 15299 | std::string origin_url = "https://origin.example.org:443"; |
| 15300 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15301 | |
| 15302 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15303 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15304 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15306 | |
| 15307 | // HTTP/1.1 data for |request1| and |request2|. |
| 15308 | MockWrite http_writes[] = { |
| 15309 | MockWrite( |
| 15310 | "GET / HTTP/1.1\r\n" |
| 15311 | "Host: alternative.example.org\r\n" |
| 15312 | "Connection: keep-alive\r\n\r\n"), |
| 15313 | MockWrite( |
| 15314 | "GET / HTTP/1.1\r\n" |
| 15315 | "Host: alternative.example.org\r\n" |
| 15316 | "Connection: keep-alive\r\n\r\n"), |
| 15317 | }; |
| 15318 | |
| 15319 | MockRead http_reads[] = { |
| 15320 | MockRead( |
| 15321 | "HTTP/1.1 200 OK\r\n" |
| 15322 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15323 | "Content-Length: 40\r\n\r\n" |
| 15324 | "first HTTP/1.1 response from alternative"), |
| 15325 | MockRead( |
| 15326 | "HTTP/1.1 200 OK\r\n" |
| 15327 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15328 | "Content-Length: 41\r\n\r\n" |
| 15329 | "second HTTP/1.1 response from alternative"), |
| 15330 | }; |
| 15331 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15332 | http_writes, arraysize(http_writes)); |
| 15333 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15334 | |
| 15335 | // This test documents that an alternate Job should not pool to an already |
| 15336 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15337 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15338 | StaticSocketDataProvider data_refused; |
| 15339 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15340 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15341 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15342 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15343 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15344 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15345 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15346 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15347 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15348 | http_server_properties->SetHttp2AlternativeService( |
| 15349 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15350 | |
| 15351 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15352 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15353 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15354 | request1.method = "GET"; |
| 15355 | request1.url = GURL(alternative_url); |
| 15356 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15357 | request1.traffic_annotation = |
| 15358 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15359 | TestCompletionCallback callback1; |
| 15360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15361 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15362 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15363 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15364 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15365 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15366 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15367 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15368 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15369 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15370 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15371 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15372 | |
| 15373 | // Request for origin.example.org, which has an alternative service. This |
| 15374 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15375 | // 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] | 15376 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15377 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15378 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15379 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15380 | request2.method = "GET"; |
| 15381 | request2.url = GURL(origin_url); |
| 15382 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15383 | request2.traffic_annotation = |
| 15384 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15385 | TestCompletionCallback callback2; |
| 15386 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15387 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15388 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15389 | |
| 15390 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15391 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15392 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15393 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15394 | request3.method = "GET"; |
| 15395 | request3.url = GURL(alternative_url); |
| 15396 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15397 | request3.traffic_annotation = |
| 15398 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15399 | TestCompletionCallback callback3; |
| 15400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15401 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15402 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15403 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15404 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15405 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15406 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15407 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15408 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15409 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15410 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15411 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15412 | } |
| 15413 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15414 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15415 | const std::string https_url = "https://www.example.org:8080/"; |
| 15416 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15417 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15418 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15419 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15420 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15421 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15422 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15423 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15424 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15425 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15426 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15427 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15428 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15429 | |
| 15430 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15431 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15432 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15433 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15434 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15435 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15436 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15437 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15438 | |
| 15439 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15440 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15441 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15442 | }; |
| 15443 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15444 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15445 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15446 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15447 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15448 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15449 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15450 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15451 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15452 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15453 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15454 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15455 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15456 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15457 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15458 | CreateMockRead(wrapped_resp1, 4), |
| 15459 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15460 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15461 | CreateMockRead(resp2, 8), |
| 15462 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15463 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15464 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15465 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15466 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15467 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15468 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15469 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15470 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15471 | session_deps_.proxy_resolution_service = |
| 15472 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15473 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15474 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15475 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15476 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15478 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15479 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15481 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15482 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15483 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15484 | |
| 15485 | // Start the first transaction to set up the SpdySession |
| 15486 | HttpRequestInfo request1; |
| 15487 | request1.method = "GET"; |
| 15488 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15489 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15490 | request1.traffic_annotation = |
| 15491 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15492 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15493 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15494 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15495 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15496 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15497 | data1.RunUntilPaused(); |
| 15498 | base::RunLoop().RunUntilIdle(); |
| 15499 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15500 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15501 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15502 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15503 | LoadTimingInfo load_timing_info1; |
| 15504 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15505 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15506 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15507 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15508 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15509 | HttpRequestInfo request2; |
| 15510 | request2.method = "GET"; |
| 15511 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15512 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15513 | request2.traffic_annotation = |
| 15514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15515 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15516 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15517 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15518 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15519 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15520 | data1.RunUntilPaused(); |
| 15521 | base::RunLoop().RunUntilIdle(); |
| 15522 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15523 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15524 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15525 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15526 | |
| 15527 | LoadTimingInfo load_timing_info2; |
| 15528 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15529 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15530 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15531 | // HTTP requests over a SPDY session should have a different connection |
| 15532 | // socket_log_id than requests over a tunnel. |
| 15533 | 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] | 15534 | } |
| 15535 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15536 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15537 | // that we do not pool other origins that resolve to the same IP when |
| 15538 | // the certificate does not match the new origin. |
| 15539 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15540 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15541 | const std::string url1 = "http://www.example.org/"; |
| 15542 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15543 | const std::string ip_addr = "1.2.3.4"; |
| 15544 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15545 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15546 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15547 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15548 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15549 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15550 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15551 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15552 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15553 | |
| 15554 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15555 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15556 | }; |
| 15557 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15558 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15559 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15560 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15561 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15562 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15563 | }; |
| 15564 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15565 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15566 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15567 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15568 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15569 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15570 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15571 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15572 | |
| 15573 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15574 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15575 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15576 | |
| 15577 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15578 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15579 | }; |
| 15580 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15581 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15582 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15583 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15584 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15585 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15586 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15587 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15588 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15589 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15590 | |
| 15591 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15592 | // all others direct. |
| 15593 | ProxyConfig proxy_config; |
| 15594 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15595 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15596 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15597 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15598 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15599 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15600 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15601 | // Load a valid cert. Note, that this does not need to |
| 15602 | // be valid for proxy because the MockSSLClientSocket does |
| 15603 | // not actually verify it. But SpdySession will use this |
| 15604 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15605 | ssl1.ssl_info.cert = |
| 15606 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15607 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15609 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15610 | |
| 15611 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15612 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15614 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15615 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15616 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15617 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15618 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15620 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15621 | |
| 15622 | // Start the first transaction to set up the SpdySession |
| 15623 | HttpRequestInfo request1; |
| 15624 | request1.method = "GET"; |
| 15625 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15626 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15627 | request1.traffic_annotation = |
| 15628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15629 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15630 | TestCompletionCallback callback1; |
| 15631 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15632 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15633 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15634 | data1.RunUntilPaused(); |
| 15635 | base::RunLoop().RunUntilIdle(); |
| 15636 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15637 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15638 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15639 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15640 | |
| 15641 | // Now, start the HTTP request |
| 15642 | HttpRequestInfo request2; |
| 15643 | request2.method = "GET"; |
| 15644 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15645 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15646 | request2.traffic_annotation = |
| 15647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15648 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15649 | TestCompletionCallback callback2; |
| 15650 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15651 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15652 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15653 | |
| 15654 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15655 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15656 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15657 | } |
| 15658 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15659 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15660 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15661 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15662 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15663 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15664 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15665 | |
| 15666 | MockRead reads1[] = { |
| 15667 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15668 | }; |
| 15669 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15670 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15671 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15672 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15673 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15674 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15675 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15676 | }; |
| 15677 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15678 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15679 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15680 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15681 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15682 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15683 | }; |
| 15684 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15685 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15686 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15687 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15688 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15689 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15690 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15692 | |
| 15693 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15694 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15695 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15696 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15697 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15698 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15699 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15700 | |
| 15701 | // Start the first transaction to set up the SpdySession and verify that |
| 15702 | // connection was closed. |
| 15703 | HttpRequestInfo request1; |
| 15704 | request1.method = "GET"; |
| 15705 | request1.url = GURL(https_url); |
| 15706 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15707 | request1.traffic_annotation = |
| 15708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15709 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15710 | TestCompletionCallback callback1; |
| 15711 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15712 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15713 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15714 | |
| 15715 | // Now, start the second request and make sure it succeeds. |
| 15716 | HttpRequestInfo request2; |
| 15717 | request2.method = "GET"; |
| 15718 | request2.url = GURL(https_url); |
| 15719 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15720 | request2.traffic_annotation = |
| 15721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15722 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15723 | TestCompletionCallback callback2; |
| 15724 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15725 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15726 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15727 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15728 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15729 | } |
| 15730 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15731 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15732 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15733 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15734 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15735 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15736 | |
| 15737 | // Use two different hosts with different IPs so they don't get pooled. |
| 15738 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15739 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15740 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15741 | |
| 15742 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15743 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15744 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15745 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15746 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15748 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15749 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15750 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15751 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15752 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15753 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15754 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15755 | SpdySerializedFrame host1_resp_body( |
| 15756 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15757 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15758 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15759 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15760 | }; |
| 15761 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15762 | // Use a separate test instance for the separate SpdySession that will be |
| 15763 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15764 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15765 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15766 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15767 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15768 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15769 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15770 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15771 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15772 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15773 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15774 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15775 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15776 | SpdySerializedFrame host2_resp_body( |
| 15777 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15778 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15779 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15780 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15781 | }; |
| 15782 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15783 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15784 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15785 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15786 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15787 | |
| 15788 | MockWrite http_write[] = { |
| 15789 | MockWrite("GET / HTTP/1.1\r\n" |
| 15790 | "Host: www.a.com\r\n" |
| 15791 | "Connection: keep-alive\r\n\r\n"), |
| 15792 | }; |
| 15793 | |
| 15794 | MockRead http_read[] = { |
| 15795 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15796 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15797 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15798 | MockRead("hello!"), |
| 15799 | }; |
| 15800 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15801 | http_write, arraysize(http_write)); |
| 15802 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15803 | |
| 15804 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15805 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15806 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15807 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15808 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15809 | |
| 15810 | TestCompletionCallback callback; |
| 15811 | HttpRequestInfo request1; |
| 15812 | request1.method = "GET"; |
| 15813 | request1.url = GURL("https://www.a.com/"); |
| 15814 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15815 | request1.traffic_annotation = |
| 15816 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15817 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15818 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15819 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15820 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15822 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15823 | |
| 15824 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15825 | ASSERT_TRUE(response); |
| 15826 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15827 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15828 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15829 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15830 | |
| 15831 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15832 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15833 | EXPECT_EQ("hello!", response_data); |
| 15834 | trans.reset(); |
| 15835 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15836 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15837 | |
| 15838 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15839 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15840 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15841 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15842 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15843 | HttpRequestInfo request2; |
| 15844 | request2.method = "GET"; |
| 15845 | request2.url = GURL("https://www.b.com/"); |
| 15846 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15847 | request2.traffic_annotation = |
| 15848 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15849 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15852 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15854 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15855 | |
| 15856 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15857 | ASSERT_TRUE(response); |
| 15858 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15859 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15860 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15861 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15862 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15863 | EXPECT_EQ("hello!", response_data); |
| 15864 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15865 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15866 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15867 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15868 | |
| 15869 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15870 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15871 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15872 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15873 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15874 | HttpRequestInfo request3; |
| 15875 | request3.method = "GET"; |
| 15876 | request3.url = GURL("http://www.a.com/"); |
| 15877 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15878 | request3.traffic_annotation = |
| 15879 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15880 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15881 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15883 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15885 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15886 | |
| 15887 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15888 | ASSERT_TRUE(response); |
| 15889 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15890 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15891 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15892 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15893 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15894 | EXPECT_EQ("hello!", response_data); |
| 15895 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15896 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15897 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15898 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15899 | } |
| 15900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15901 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15902 | HttpRequestInfo request; |
| 15903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15904 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15905 | request.traffic_annotation = |
| 15906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15910 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15911 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15912 | StaticSocketDataProvider data; |
| 15913 | data.set_connect_data(mock_connect); |
| 15914 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15915 | |
| 15916 | TestCompletionCallback callback; |
| 15917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15919 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15920 | |
| 15921 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15922 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15923 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15924 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15925 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15926 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15927 | |
| 15928 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15929 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15930 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15931 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15932 | |
| 15933 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15934 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15935 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15936 | } |
| 15937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15938 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15939 | HttpRequestInfo request; |
| 15940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15941 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15942 | request.traffic_annotation = |
| 15943 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15947 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15948 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15949 | StaticSocketDataProvider data; |
| 15950 | data.set_connect_data(mock_connect); |
| 15951 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15952 | |
| 15953 | TestCompletionCallback callback; |
| 15954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15955 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15957 | |
| 15958 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15959 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15960 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15961 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15962 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15963 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15964 | |
| 15965 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15966 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15967 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15968 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15969 | |
| 15970 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15971 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15972 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15973 | } |
| 15974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15975 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15976 | HttpRequestInfo request; |
| 15977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15978 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15979 | request.traffic_annotation = |
| 15980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15981 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15984 | |
| 15985 | MockWrite data_writes[] = { |
| 15986 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15987 | }; |
| 15988 | MockRead data_reads[] = { |
| 15989 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15990 | }; |
| 15991 | |
| 15992 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15993 | data_writes, arraysize(data_writes)); |
| 15994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15995 | |
| 15996 | TestCompletionCallback callback; |
| 15997 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15998 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16000 | |
| 16001 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16002 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16003 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16004 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16005 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16006 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16007 | } |
| 16008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16009 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16010 | HttpRequestInfo request; |
| 16011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16012 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16013 | request.traffic_annotation = |
| 16014 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16015 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16016 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16017 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16018 | |
| 16019 | MockWrite data_writes[] = { |
| 16020 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16021 | }; |
| 16022 | MockRead data_reads[] = { |
| 16023 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16024 | }; |
| 16025 | |
| 16026 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16027 | data_writes, arraysize(data_writes)); |
| 16028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16029 | |
| 16030 | TestCompletionCallback callback; |
| 16031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16034 | |
| 16035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16036 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16037 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16038 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16039 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16040 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16041 | } |
| 16042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16043 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16044 | HttpRequestInfo request; |
| 16045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16046 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16047 | request.traffic_annotation = |
| 16048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16049 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16052 | |
| 16053 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16054 | MockWrite( |
| 16055 | "GET / HTTP/1.1\r\n" |
| 16056 | "Host: www.example.org\r\n" |
| 16057 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16058 | }; |
| 16059 | MockRead data_reads[] = { |
| 16060 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16061 | }; |
| 16062 | |
| 16063 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16064 | data_writes, arraysize(data_writes)); |
| 16065 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16066 | |
| 16067 | TestCompletionCallback callback; |
| 16068 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16069 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16071 | |
| 16072 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16073 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16074 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16075 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16076 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16077 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16078 | } |
| 16079 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16080 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16081 | HttpRequestInfo request; |
| 16082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16083 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16084 | request.traffic_annotation = |
| 16085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16089 | |
| 16090 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16091 | MockWrite( |
| 16092 | "GET / HTTP/1.1\r\n" |
| 16093 | "Host: www.example.org\r\n" |
| 16094 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16095 | }; |
| 16096 | MockRead data_reads[] = { |
| 16097 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16098 | }; |
| 16099 | |
| 16100 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16101 | data_writes, arraysize(data_writes)); |
| 16102 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16103 | |
| 16104 | TestCompletionCallback callback; |
| 16105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16106 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16108 | |
| 16109 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16110 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16111 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16112 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16113 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16114 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16115 | } |
| 16116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16117 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16118 | HttpRequestInfo request; |
| 16119 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16120 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16121 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16122 | request.traffic_annotation = |
| 16123 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16124 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16127 | |
| 16128 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16129 | MockWrite( |
| 16130 | "GET / HTTP/1.1\r\n" |
| 16131 | "Host: www.example.org\r\n" |
| 16132 | "Connection: keep-alive\r\n" |
| 16133 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16134 | }; |
| 16135 | MockRead data_reads[] = { |
| 16136 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16137 | "Content-Length: 5\r\n\r\n" |
| 16138 | "hello"), |
| 16139 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16140 | }; |
| 16141 | |
| 16142 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 16143 | data_writes, arraysize(data_writes)); |
| 16144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16145 | |
| 16146 | TestCompletionCallback callback; |
| 16147 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16148 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16150 | |
| 16151 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16152 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16153 | |
| 16154 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16155 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16156 | std::string foo; |
| 16157 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16158 | EXPECT_EQ("bar", foo); |
| 16159 | } |
| 16160 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16161 | namespace { |
| 16162 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16163 | // Fake HttpStream that simply records calls to SetPriority(). |
| 16164 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16165 | public base::SupportsWeakPtr<FakeStream> { |
| 16166 | public: |
| 16167 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16168 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16169 | |
| 16170 | RequestPriority priority() const { return priority_; } |
| 16171 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16172 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 16173 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16174 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16175 | const NetLogWithSource& net_log, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16176 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16177 | return ERR_IO_PENDING; |
| 16178 | } |
| 16179 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16180 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 16181 | HttpResponseInfo* response, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16182 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16183 | ADD_FAILURE(); |
| 16184 | return ERR_UNEXPECTED; |
| 16185 | } |
| 16186 | |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16187 | int ReadResponseHeaders(CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16188 | ADD_FAILURE(); |
| 16189 | return ERR_UNEXPECTED; |
| 16190 | } |
| 16191 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16192 | int ReadResponseBody(IOBuffer* buf, |
| 16193 | int buf_len, |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 16194 | CompletionOnceCallback callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16195 | ADD_FAILURE(); |
| 16196 | return ERR_UNEXPECTED; |
| 16197 | } |
| 16198 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16199 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16200 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16201 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16202 | ADD_FAILURE(); |
| 16203 | return false; |
| 16204 | } |
| 16205 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16206 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16207 | ADD_FAILURE(); |
| 16208 | return false; |
| 16209 | } |
| 16210 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16211 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16212 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16213 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16214 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16215 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 16216 | ADD_FAILURE(); |
| 16217 | return 0; |
| 16218 | } |
| 16219 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16220 | int64_t GetTotalSentBytes() const override { |
| 16221 | ADD_FAILURE(); |
| 16222 | return 0; |
| 16223 | } |
| 16224 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16225 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16226 | ADD_FAILURE(); |
| 16227 | return false; |
| 16228 | } |
| 16229 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16230 | bool GetAlternativeService( |
| 16231 | AlternativeService* alternative_service) const override { |
| 16232 | ADD_FAILURE(); |
| 16233 | return false; |
| 16234 | } |
| 16235 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16236 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 16237 | |
| 16238 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16239 | ADD_FAILURE(); |
| 16240 | } |
| 16241 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16242 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16243 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16244 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16245 | TokenBindingType tb_type, |
| 16246 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16247 | ADD_FAILURE(); |
| 16248 | return ERR_NOT_IMPLEMENTED; |
| 16249 | } |
| 16250 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16251 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16252 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16253 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16254 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16255 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16256 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 16257 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 16258 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 16259 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 16260 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16261 | private: |
| 16262 | RequestPriority priority_; |
| 16263 | |
| 16264 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 16265 | }; |
| 16266 | |
| 16267 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 16268 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16269 | class FakeStreamRequest : public HttpStreamRequest, |
| 16270 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 16271 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16272 | FakeStreamRequest(RequestPriority priority, |
| 16273 | HttpStreamRequest::Delegate* delegate) |
| 16274 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16275 | delegate_(delegate), |
| 16276 | websocket_stream_create_helper_(NULL) {} |
| 16277 | |
| 16278 | FakeStreamRequest(RequestPriority priority, |
| 16279 | HttpStreamRequest::Delegate* delegate, |
| 16280 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 16281 | : priority_(priority), |
| 16282 | delegate_(delegate), |
| 16283 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16284 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16285 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16286 | |
| 16287 | RequestPriority priority() const { return priority_; } |
| 16288 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16289 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 16290 | websocket_stream_create_helper() const { |
| 16291 | return websocket_stream_create_helper_; |
| 16292 | } |
| 16293 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16294 | // Create a new FakeStream and pass it to the request's |
| 16295 | // delegate. Returns a weak pointer to the FakeStream. |
| 16296 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16297 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16298 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 16299 | // immediately delete |fake_stream|. |
| 16300 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 16301 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16302 | return weak_stream; |
| 16303 | } |
| 16304 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 16305 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16306 | ADD_FAILURE(); |
| 16307 | return ERR_UNEXPECTED; |
| 16308 | } |
| 16309 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16310 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16311 | ADD_FAILURE(); |
| 16312 | return LoadState(); |
| 16313 | } |
| 16314 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16315 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16316 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16317 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16318 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 16319 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16320 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16321 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16322 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16323 | const ConnectionAttempts& connection_attempts() const override { |
| 16324 | static ConnectionAttempts no_attempts; |
| 16325 | return no_attempts; |
| 16326 | } |
| 16327 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16328 | private: |
| 16329 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16330 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16331 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16332 | |
| 16333 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 16334 | }; |
| 16335 | |
| 16336 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 16337 | class FakeStreamFactory : public HttpStreamFactory { |
| 16338 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16339 | FakeStreamFactory() = default; |
| 16340 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16341 | |
| 16342 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 16343 | // RequestStream() (which may be NULL if it was destroyed already). |
| 16344 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 16345 | return last_stream_request_; |
| 16346 | } |
| 16347 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16348 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 16349 | const HttpRequestInfo& info, |
| 16350 | RequestPriority priority, |
| 16351 | const SSLConfig& server_ssl_config, |
| 16352 | const SSLConfig& proxy_ssl_config, |
| 16353 | HttpStreamRequest::Delegate* delegate, |
| 16354 | bool enable_ip_based_pooling, |
| 16355 | bool enable_alternative_services, |
| 16356 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16357 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16358 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16359 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16360 | } |
| 16361 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16362 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16363 | const HttpRequestInfo& info, |
| 16364 | RequestPriority priority, |
| 16365 | const SSLConfig& server_ssl_config, |
| 16366 | const SSLConfig& proxy_ssl_config, |
| 16367 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16368 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16369 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16370 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 16371 | NOTREACHED(); |
| 16372 | return nullptr; |
| 16373 | } |
| 16374 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16375 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16376 | const HttpRequestInfo& info, |
| 16377 | RequestPriority priority, |
| 16378 | const SSLConfig& server_ssl_config, |
| 16379 | const SSLConfig& proxy_ssl_config, |
| 16380 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 16381 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 16382 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 16383 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16384 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16385 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16386 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16387 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16388 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16389 | } |
| 16390 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16391 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16392 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16393 | ADD_FAILURE(); |
| 16394 | } |
| 16395 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 16396 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16397 | ADD_FAILURE(); |
| 16398 | return NULL; |
| 16399 | } |
| 16400 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 16401 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 16402 | const std::string& parent_absolute_name) const override { |
| 16403 | ADD_FAILURE(); |
| 16404 | } |
| 16405 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16406 | private: |
| 16407 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 16408 | |
| 16409 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 16410 | }; |
| 16411 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16412 | } // namespace |
| 16413 | |
| 16414 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16415 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16416 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16418 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16419 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16420 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16421 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16422 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16423 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16424 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16425 | request.traffic_annotation = |
| 16426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16427 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16428 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16429 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16430 | TestCompletionCallback callback; |
| 16431 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16432 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16433 | |
| 16434 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16435 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16436 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16437 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16438 | } |
| 16439 | |
| 16440 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16441 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16442 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16444 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16445 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16446 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16447 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16448 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16449 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16450 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16451 | request.traffic_annotation = |
| 16452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16453 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16454 | TestCompletionCallback callback; |
| 16455 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16456 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16457 | |
| 16458 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16459 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16460 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16461 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16462 | |
| 16463 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16464 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16465 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16466 | } |
| 16467 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16468 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16469 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16470 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16472 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16473 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16474 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16475 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16476 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16477 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16478 | |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16479 | request.traffic_annotation = |
| 16480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 16481 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16482 | TestCompletionCallback callback; |
| 16483 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16484 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16485 | |
| 16486 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16487 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16488 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16489 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16490 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16491 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16492 | |
| 16493 | trans.SetPriority(LOWEST); |
| 16494 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16495 | } |
| 16496 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16497 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16498 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16499 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16500 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16501 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16502 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16503 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16504 | |
| 16505 | // Set up SSL request. |
| 16506 | |
| 16507 | HttpRequestInfo ssl_request; |
| 16508 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16509 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16510 | ssl_request.traffic_annotation = |
| 16511 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16512 | |
| 16513 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16514 | MockWrite( |
| 16515 | "GET / HTTP/1.1\r\n" |
| 16516 | "Host: www.example.org\r\n" |
| 16517 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16518 | }; |
| 16519 | MockRead ssl_reads[] = { |
| 16520 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16521 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16522 | MockRead("hello world"), |
| 16523 | MockRead(SYNCHRONOUS, OK), |
| 16524 | }; |
| 16525 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16526 | ssl_writes, arraysize(ssl_writes)); |
| 16527 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16528 | |
| 16529 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16531 | |
| 16532 | // Set up HTTP request. |
| 16533 | |
| 16534 | HttpRequestInfo http_request; |
| 16535 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16536 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16537 | http_request.traffic_annotation = |
| 16538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16539 | |
| 16540 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16541 | MockWrite( |
| 16542 | "GET / HTTP/1.1\r\n" |
| 16543 | "Host: www.example.org\r\n" |
| 16544 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16545 | }; |
| 16546 | MockRead http_reads[] = { |
| 16547 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16548 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16549 | MockRead("falafel"), |
| 16550 | MockRead(SYNCHRONOUS, OK), |
| 16551 | }; |
| 16552 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16553 | http_writes, arraysize(http_writes)); |
| 16554 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16557 | |
| 16558 | // Start the SSL request. |
| 16559 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16560 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16561 | ASSERT_EQ(ERR_IO_PENDING, |
| 16562 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16563 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16564 | |
| 16565 | // Start the HTTP request. Pool should stall. |
| 16566 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16567 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16568 | ASSERT_EQ(ERR_IO_PENDING, |
| 16569 | http_trans.Start(&http_request, http_callback.callback(), |
| 16570 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16571 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16572 | |
| 16573 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16574 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16575 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16576 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16577 | EXPECT_EQ("hello world", response_data); |
| 16578 | |
| 16579 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16580 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16581 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16582 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16583 | |
| 16584 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16585 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16586 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16587 | EXPECT_EQ("falafel", response_data); |
| 16588 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16589 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16590 | } |
| 16591 | |
| 16592 | // Tests that when a SSL connection is established but there's no corresponding |
| 16593 | // request that needs it, the new socket is closed if the transport socket pool |
| 16594 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16595 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16596 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16597 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16598 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16599 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16600 | |
| 16601 | // Set up an ssl request. |
| 16602 | |
| 16603 | HttpRequestInfo ssl_request; |
| 16604 | ssl_request.method = "GET"; |
| 16605 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16606 | ssl_request.traffic_annotation = |
| 16607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16608 | |
| 16609 | // No data will be sent on the SSL socket. |
| 16610 | StaticSocketDataProvider ssl_data; |
| 16611 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16612 | |
| 16613 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16614 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16615 | |
| 16616 | // Set up HTTP request. |
| 16617 | |
| 16618 | HttpRequestInfo http_request; |
| 16619 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16620 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16621 | http_request.traffic_annotation = |
| 16622 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16623 | |
| 16624 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16625 | MockWrite( |
| 16626 | "GET / HTTP/1.1\r\n" |
| 16627 | "Host: www.example.org\r\n" |
| 16628 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16629 | }; |
| 16630 | MockRead http_reads[] = { |
| 16631 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16632 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16633 | MockRead("falafel"), |
| 16634 | MockRead(SYNCHRONOUS, OK), |
| 16635 | }; |
| 16636 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16637 | http_writes, arraysize(http_writes)); |
| 16638 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16639 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16640 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16641 | |
| 16642 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16643 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16644 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16645 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16646 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16647 | |
| 16648 | // Start the HTTP request. Pool should stall. |
| 16649 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16650 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16651 | ASSERT_EQ(ERR_IO_PENDING, |
| 16652 | http_trans.Start(&http_request, http_callback.callback(), |
| 16653 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16654 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16655 | |
| 16656 | // The SSL connection will automatically be closed once the connection is |
| 16657 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16658 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16659 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16660 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16661 | EXPECT_EQ("falafel", response_data); |
| 16662 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16663 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16664 | } |
| 16665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16666 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16667 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16668 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16669 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16670 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16671 | |
| 16672 | HttpRequestInfo request; |
| 16673 | request.method = "POST"; |
| 16674 | request.url = GURL("http://www.foo.com/"); |
| 16675 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16676 | request.traffic_annotation = |
| 16677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16681 | // Send headers successfully, but get an error while sending the body. |
| 16682 | MockWrite data_writes[] = { |
| 16683 | MockWrite("POST / HTTP/1.1\r\n" |
| 16684 | "Host: www.foo.com\r\n" |
| 16685 | "Connection: keep-alive\r\n" |
| 16686 | "Content-Length: 3\r\n\r\n"), |
| 16687 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16688 | }; |
| 16689 | |
| 16690 | MockRead data_reads[] = { |
| 16691 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16692 | MockRead("hello world"), |
| 16693 | MockRead(SYNCHRONOUS, OK), |
| 16694 | }; |
| 16695 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16696 | arraysize(data_writes)); |
| 16697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16698 | |
| 16699 | TestCompletionCallback callback; |
| 16700 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16701 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16702 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16703 | |
| 16704 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16705 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16706 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16707 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16708 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16709 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16710 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16711 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16712 | |
| 16713 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16714 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16715 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16716 | EXPECT_EQ("hello world", response_data); |
| 16717 | } |
| 16718 | |
| 16719 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16720 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16721 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16722 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16724 | MockWrite data_writes[] = { |
| 16725 | MockWrite("GET / HTTP/1.1\r\n" |
| 16726 | "Host: www.foo.com\r\n" |
| 16727 | "Connection: keep-alive\r\n\r\n"), |
| 16728 | MockWrite("POST / HTTP/1.1\r\n" |
| 16729 | "Host: www.foo.com\r\n" |
| 16730 | "Connection: keep-alive\r\n" |
| 16731 | "Content-Length: 3\r\n\r\n"), |
| 16732 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16733 | }; |
| 16734 | |
| 16735 | MockRead data_reads[] = { |
| 16736 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16737 | "Content-Length: 14\r\n\r\n"), |
| 16738 | MockRead("first response"), |
| 16739 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16740 | "Content-Length: 15\r\n\r\n"), |
| 16741 | MockRead("second response"), |
| 16742 | MockRead(SYNCHRONOUS, OK), |
| 16743 | }; |
| 16744 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16745 | arraysize(data_writes)); |
| 16746 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16747 | |
| 16748 | TestCompletionCallback callback; |
| 16749 | HttpRequestInfo request1; |
| 16750 | request1.method = "GET"; |
| 16751 | request1.url = GURL("http://www.foo.com/"); |
| 16752 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16753 | request1.traffic_annotation = |
| 16754 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16755 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16756 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16757 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16758 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16759 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16760 | |
| 16761 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16763 | |
| 16764 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16765 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16766 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16767 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16768 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16769 | |
| 16770 | std::string response_data1; |
| 16771 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16773 | EXPECT_EQ("first response", response_data1); |
| 16774 | // Delete the transaction to release the socket back into the socket pool. |
| 16775 | trans1.reset(); |
| 16776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16777 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16778 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16779 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16780 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16781 | |
| 16782 | HttpRequestInfo request2; |
| 16783 | request2.method = "POST"; |
| 16784 | request2.url = GURL("http://www.foo.com/"); |
| 16785 | request2.upload_data_stream = &upload_data_stream; |
| 16786 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16787 | request2.traffic_annotation = |
| 16788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16790 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16791 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16793 | |
| 16794 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16795 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16797 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16798 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16799 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16800 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16801 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16802 | |
| 16803 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16804 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16806 | EXPECT_EQ("second response", response_data2); |
| 16807 | } |
| 16808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16809 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16810 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16811 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16812 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16813 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16814 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16815 | |
| 16816 | HttpRequestInfo request; |
| 16817 | request.method = "POST"; |
| 16818 | request.url = GURL("http://www.foo.com/"); |
| 16819 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16820 | request.traffic_annotation = |
| 16821 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16825 | // Send headers successfully, but get an error while sending the body. |
| 16826 | MockWrite data_writes[] = { |
| 16827 | MockWrite("POST / HTTP/1.1\r\n" |
| 16828 | "Host: www.foo.com\r\n" |
| 16829 | "Connection: keep-alive\r\n" |
| 16830 | "Content-Length: 3\r\n\r\n" |
| 16831 | "fo"), |
| 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 tests the more common case than the previous test, where headers and |
| 16865 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16866 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16867 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16868 | |
| 16869 | HttpRequestInfo request; |
| 16870 | request.method = "POST"; |
| 16871 | request.url = GURL("http://www.foo.com/"); |
| 16872 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16873 | request.traffic_annotation = |
| 16874 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16875 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16878 | // Send headers successfully, but get an error while sending the body. |
| 16879 | MockWrite data_writes[] = { |
| 16880 | MockWrite("POST / HTTP/1.1\r\n" |
| 16881 | "Host: www.foo.com\r\n" |
| 16882 | "Connection: keep-alive\r\n" |
| 16883 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16884 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16885 | }; |
| 16886 | |
| 16887 | MockRead data_reads[] = { |
| 16888 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16889 | MockRead("hello world"), |
| 16890 | MockRead(SYNCHRONOUS, OK), |
| 16891 | }; |
| 16892 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16893 | arraysize(data_writes)); |
| 16894 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16895 | |
| 16896 | TestCompletionCallback callback; |
| 16897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16898 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16900 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16901 | // they can't be merged with the body in a single send. Not currently |
| 16902 | // necessary since a chunked body is never merged with headers, but this makes |
| 16903 | // the test more future proof. |
| 16904 | base::RunLoop().RunUntilIdle(); |
| 16905 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16906 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16907 | |
| 16908 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16912 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16913 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16914 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16915 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16916 | |
| 16917 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16918 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16919 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16920 | EXPECT_EQ("hello world", response_data); |
| 16921 | } |
| 16922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16923 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16924 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16925 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16926 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16927 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16928 | |
| 16929 | HttpRequestInfo request; |
| 16930 | request.method = "POST"; |
| 16931 | request.url = GURL("http://www.foo.com/"); |
| 16932 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16933 | request.traffic_annotation = |
| 16934 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16938 | |
| 16939 | MockWrite data_writes[] = { |
| 16940 | MockWrite("POST / HTTP/1.1\r\n" |
| 16941 | "Host: www.foo.com\r\n" |
| 16942 | "Connection: keep-alive\r\n" |
| 16943 | "Content-Length: 3\r\n\r\n"), |
| 16944 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16945 | }; |
| 16946 | |
| 16947 | MockRead data_reads[] = { |
| 16948 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16949 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16950 | MockRead("hello world"), |
| 16951 | MockRead(SYNCHRONOUS, OK), |
| 16952 | }; |
| 16953 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16954 | arraysize(data_writes)); |
| 16955 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16956 | |
| 16957 | TestCompletionCallback callback; |
| 16958 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16959 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16961 | |
| 16962 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16963 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16964 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16965 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16966 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16967 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16968 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16969 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16970 | |
| 16971 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16972 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16974 | EXPECT_EQ("hello world", response_data); |
| 16975 | } |
| 16976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16977 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16978 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16979 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16980 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16981 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16982 | |
| 16983 | HttpRequestInfo request; |
| 16984 | request.method = "POST"; |
| 16985 | request.url = GURL("http://www.foo.com/"); |
| 16986 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16987 | request.traffic_annotation = |
| 16988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16992 | // Send headers successfully, but get an error while sending the body. |
| 16993 | MockWrite data_writes[] = { |
| 16994 | MockWrite("POST / HTTP/1.1\r\n" |
| 16995 | "Host: www.foo.com\r\n" |
| 16996 | "Connection: keep-alive\r\n" |
| 16997 | "Content-Length: 3\r\n\r\n"), |
| 16998 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16999 | }; |
| 17000 | |
| 17001 | MockRead data_reads[] = { |
| 17002 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17003 | MockRead("hello world"), |
| 17004 | MockRead(SYNCHRONOUS, OK), |
| 17005 | }; |
| 17006 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17007 | arraysize(data_writes)); |
| 17008 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17009 | |
| 17010 | TestCompletionCallback callback; |
| 17011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17012 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17014 | |
| 17015 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17016 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17017 | } |
| 17018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17019 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17020 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17021 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17022 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17023 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17024 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17025 | |
| 17026 | HttpRequestInfo request; |
| 17027 | request.method = "POST"; |
| 17028 | request.url = GURL("http://www.foo.com/"); |
| 17029 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17030 | request.traffic_annotation = |
| 17031 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17035 | // Send headers successfully, but get an error while sending the body. |
| 17036 | MockWrite data_writes[] = { |
| 17037 | MockWrite("POST / HTTP/1.1\r\n" |
| 17038 | "Host: www.foo.com\r\n" |
| 17039 | "Connection: keep-alive\r\n" |
| 17040 | "Content-Length: 3\r\n\r\n"), |
| 17041 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17042 | }; |
| 17043 | |
| 17044 | MockRead data_reads[] = { |
| 17045 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17046 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17047 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17048 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17049 | MockRead(SYNCHRONOUS, OK), |
| 17050 | }; |
| 17051 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17052 | arraysize(data_writes)); |
| 17053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17054 | |
| 17055 | TestCompletionCallback callback; |
| 17056 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17057 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17059 | |
| 17060 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17061 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17062 | } |
| 17063 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17064 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17065 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17066 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17067 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17068 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17069 | |
| 17070 | HttpRequestInfo request; |
| 17071 | request.method = "POST"; |
| 17072 | request.url = GURL("http://www.foo.com/"); |
| 17073 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17074 | request.traffic_annotation = |
| 17075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17079 | // Send headers successfully, but get an error while sending the body. |
| 17080 | MockWrite data_writes[] = { |
| 17081 | MockWrite("POST / HTTP/1.1\r\n" |
| 17082 | "Host: www.foo.com\r\n" |
| 17083 | "Connection: keep-alive\r\n" |
| 17084 | "Content-Length: 3\r\n\r\n"), |
| 17085 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17086 | }; |
| 17087 | |
| 17088 | MockRead data_reads[] = { |
| 17089 | MockRead("HTTP 0.9 rocks!"), |
| 17090 | MockRead(SYNCHRONOUS, OK), |
| 17091 | }; |
| 17092 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17093 | arraysize(data_writes)); |
| 17094 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17095 | |
| 17096 | TestCompletionCallback callback; |
| 17097 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17098 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17100 | |
| 17101 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17102 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17103 | } |
| 17104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17105 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17106 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17107 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17108 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17109 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17110 | |
| 17111 | HttpRequestInfo request; |
| 17112 | request.method = "POST"; |
| 17113 | request.url = GURL("http://www.foo.com/"); |
| 17114 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17115 | request.traffic_annotation = |
| 17116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17120 | // Send headers successfully, but get an error while sending the body. |
| 17121 | MockWrite data_writes[] = { |
| 17122 | MockWrite("POST / HTTP/1.1\r\n" |
| 17123 | "Host: www.foo.com\r\n" |
| 17124 | "Connection: keep-alive\r\n" |
| 17125 | "Content-Length: 3\r\n\r\n"), |
| 17126 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17127 | }; |
| 17128 | |
| 17129 | MockRead data_reads[] = { |
| 17130 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17131 | MockRead(SYNCHRONOUS, OK), |
| 17132 | }; |
| 17133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17134 | arraysize(data_writes)); |
| 17135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17136 | |
| 17137 | TestCompletionCallback callback; |
| 17138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17139 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17141 | |
| 17142 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17143 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17144 | } |
| 17145 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17146 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17147 | |
| 17148 | namespace { |
| 17149 | |
| 17150 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17151 | headers->SetHeader("Connection", "Upgrade"); |
| 17152 | headers->SetHeader("Upgrade", "websocket"); |
| 17153 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17154 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17155 | } |
| 17156 | |
| 17157 | } // namespace |
| 17158 | |
| 17159 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 17160 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 17161 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 17162 | // that the different schemes work. |
| 17163 | std::string test_cases[] = {"ws://www.example.org/", |
| 17164 | "wss://www.example.org/"}; |
| 17165 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 17166 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17167 | HttpNetworkSessionPeer peer(session.get()); |
| 17168 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 17169 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
| 17170 | |
| 17171 | HttpRequestInfo request; |
| 17172 | request.method = "GET"; |
| 17173 | request.url = GURL(test_cases[i]); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17174 | request.traffic_annotation = |
| 17175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17176 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17177 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17178 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17179 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17180 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 17181 | &websocket_stream_create_helper); |
| 17182 | |
| 17183 | TestCompletionCallback callback; |
| 17184 | EXPECT_EQ(ERR_IO_PENDING, |
| 17185 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 17186 | |
| 17187 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 17188 | fake_factory->last_stream_request(); |
| 17189 | ASSERT_TRUE(fake_request); |
| 17190 | EXPECT_EQ(&websocket_stream_create_helper, |
| 17191 | fake_request->websocket_stream_create_helper()); |
| 17192 | } |
| 17193 | } |
| 17194 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17195 | // Verify that proxy headers are not sent to the destination server when |
| 17196 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17197 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17198 | HttpRequestInfo request; |
| 17199 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17200 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17201 | request.traffic_annotation = |
| 17202 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17203 | AddWebSocketHeaders(&request.extra_headers); |
| 17204 | |
| 17205 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17206 | session_deps_.proxy_resolution_service = |
| 17207 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17208 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17210 | |
| 17211 | // Since a proxy is configured, try to establish a tunnel. |
| 17212 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17213 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17214 | "Host: www.example.org:443\r\n" |
| 17215 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17216 | |
| 17217 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17218 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17219 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17220 | "Host: www.example.org:443\r\n" |
| 17221 | "Proxy-Connection: keep-alive\r\n" |
| 17222 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17223 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17224 | MockWrite("GET / HTTP/1.1\r\n" |
| 17225 | "Host: www.example.org\r\n" |
| 17226 | "Connection: Upgrade\r\n" |
| 17227 | "Upgrade: websocket\r\n" |
| 17228 | "Origin: http://www.example.org\r\n" |
| 17229 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17230 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17231 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17232 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17233 | |
| 17234 | // The proxy responds to the connect with a 407, using a persistent |
| 17235 | // connection. |
| 17236 | MockRead data_reads[] = { |
| 17237 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17238 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17239 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17240 | "Content-Length: 0\r\n" |
| 17241 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17242 | |
| 17243 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17244 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17245 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17246 | "Upgrade: websocket\r\n" |
| 17247 | "Connection: Upgrade\r\n" |
| 17248 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17249 | |
| 17250 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17251 | arraysize(data_writes)); |
| 17252 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17253 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17255 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17256 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17257 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17258 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17259 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17260 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17261 | &websocket_stream_create_helper); |
| 17262 | |
| 17263 | { |
| 17264 | TestCompletionCallback callback; |
| 17265 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17266 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17268 | |
| 17269 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17270 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17271 | } |
| 17272 | |
| 17273 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17274 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17275 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17276 | EXPECT_EQ(407, response->headers->response_code()); |
| 17277 | |
| 17278 | { |
| 17279 | TestCompletionCallback callback; |
| 17280 | |
| 17281 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17282 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17284 | |
| 17285 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17286 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17287 | } |
| 17288 | |
| 17289 | response = trans->GetResponseInfo(); |
| 17290 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17291 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17292 | |
| 17293 | EXPECT_EQ(101, response->headers->response_code()); |
| 17294 | |
| 17295 | trans.reset(); |
| 17296 | session->CloseAllConnections(); |
| 17297 | } |
| 17298 | |
| 17299 | // Verify that proxy headers are not sent to the destination server when |
| 17300 | // establishing a tunnel for an insecure WebSocket connection. |
| 17301 | // This requires the authentication info to be injected into the auth cache |
| 17302 | // due to crbug.com/395064 |
| 17303 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17304 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17305 | HttpRequestInfo request; |
| 17306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17307 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17308 | request.traffic_annotation = |
| 17309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17310 | AddWebSocketHeaders(&request.extra_headers); |
| 17311 | |
| 17312 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17313 | session_deps_.proxy_resolution_service = |
| 17314 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17315 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17317 | |
| 17318 | MockWrite data_writes[] = { |
| 17319 | // Try to establish a tunnel for the WebSocket connection, with |
| 17320 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17321 | // they cannot and will not use the same TCP/IP connection as the |
| 17322 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17323 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17324 | "Host: www.example.org:80\r\n" |
| 17325 | "Proxy-Connection: keep-alive\r\n" |
| 17326 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17327 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17328 | MockWrite("GET / HTTP/1.1\r\n" |
| 17329 | "Host: www.example.org\r\n" |
| 17330 | "Connection: Upgrade\r\n" |
| 17331 | "Upgrade: websocket\r\n" |
| 17332 | "Origin: http://www.example.org\r\n" |
| 17333 | "Sec-WebSocket-Version: 13\r\n" |
| 17334 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17335 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17336 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17337 | |
| 17338 | MockRead data_reads[] = { |
| 17339 | // HTTP CONNECT with credentials. |
| 17340 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17341 | |
| 17342 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17343 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17344 | "Upgrade: websocket\r\n" |
| 17345 | "Connection: Upgrade\r\n" |
| 17346 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17347 | |
| 17348 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17349 | arraysize(data_writes)); |
| 17350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17351 | |
| 17352 | session->http_auth_cache()->Add( |
| 17353 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17354 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17355 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17356 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17357 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17358 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17359 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17360 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17361 | &websocket_stream_create_helper); |
| 17362 | |
| 17363 | TestCompletionCallback callback; |
| 17364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17365 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17367 | |
| 17368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17369 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17370 | |
| 17371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17372 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17373 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17374 | |
| 17375 | EXPECT_EQ(101, response->headers->response_code()); |
| 17376 | |
| 17377 | trans.reset(); |
| 17378 | session->CloseAllConnections(); |
| 17379 | } |
| 17380 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17381 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17383 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17384 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17385 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17386 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17387 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17388 | |
| 17389 | HttpRequestInfo request; |
| 17390 | request.method = "POST"; |
| 17391 | request.url = GURL("http://www.foo.com/"); |
| 17392 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17393 | request.traffic_annotation = |
| 17394 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17395 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17398 | MockWrite data_writes[] = { |
| 17399 | MockWrite("POST / HTTP/1.1\r\n" |
| 17400 | "Host: www.foo.com\r\n" |
| 17401 | "Connection: keep-alive\r\n" |
| 17402 | "Content-Length: 3\r\n\r\n"), |
| 17403 | MockWrite("foo"), |
| 17404 | }; |
| 17405 | |
| 17406 | MockRead data_reads[] = { |
| 17407 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17408 | MockRead(SYNCHRONOUS, OK), |
| 17409 | }; |
| 17410 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17411 | arraysize(data_writes)); |
| 17412 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17413 | |
| 17414 | TestCompletionCallback callback; |
| 17415 | |
| 17416 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17417 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17418 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17419 | |
| 17420 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17421 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17422 | |
| 17423 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17424 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17425 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17426 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17427 | } |
| 17428 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17429 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17430 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17431 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17432 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17433 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17434 | |
| 17435 | HttpRequestInfo request; |
| 17436 | request.method = "POST"; |
| 17437 | request.url = GURL("http://www.foo.com/"); |
| 17438 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17439 | request.traffic_annotation = |
| 17440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17444 | MockWrite data_writes[] = { |
| 17445 | MockWrite("POST / HTTP/1.1\r\n" |
| 17446 | "Host: www.foo.com\r\n" |
| 17447 | "Connection: keep-alive\r\n" |
| 17448 | "Content-Length: 3\r\n\r\n"), |
| 17449 | MockWrite("foo"), |
| 17450 | }; |
| 17451 | |
| 17452 | MockRead data_reads[] = { |
| 17453 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17454 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17455 | MockRead(SYNCHRONOUS, OK), |
| 17456 | }; |
| 17457 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17458 | arraysize(data_writes)); |
| 17459 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17460 | |
| 17461 | TestCompletionCallback callback; |
| 17462 | |
| 17463 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17464 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17465 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17466 | |
| 17467 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17468 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17469 | |
| 17470 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17471 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17472 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17473 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17474 | } |
| 17475 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17476 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17477 | ChunkedUploadDataStream upload_data_stream(0); |
| 17478 | |
| 17479 | HttpRequestInfo request; |
| 17480 | request.method = "POST"; |
| 17481 | request.url = GURL("http://www.foo.com/"); |
| 17482 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17483 | request.traffic_annotation = |
| 17484 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17485 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17488 | // Send headers successfully, but get an error while sending the body. |
| 17489 | MockWrite data_writes[] = { |
| 17490 | MockWrite("POST / HTTP/1.1\r\n" |
| 17491 | "Host: www.foo.com\r\n" |
| 17492 | "Connection: keep-alive\r\n" |
| 17493 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17494 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17495 | }; |
| 17496 | |
| 17497 | MockRead data_reads[] = { |
| 17498 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17499 | MockRead(SYNCHRONOUS, OK), |
| 17500 | }; |
| 17501 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17502 | arraysize(data_writes)); |
| 17503 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17504 | |
| 17505 | TestCompletionCallback callback; |
| 17506 | |
| 17507 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17508 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17509 | |
| 17510 | base::RunLoop().RunUntilIdle(); |
| 17511 | upload_data_stream.AppendData("f", 1, false); |
| 17512 | |
| 17513 | base::RunLoop().RunUntilIdle(); |
| 17514 | upload_data_stream.AppendData("oo", 2, true); |
| 17515 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17516 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17517 | |
| 17518 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17519 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17520 | |
| 17521 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17522 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17523 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17524 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17525 | } |
| 17526 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17527 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17528 | // the unthrottled state are not blocked. |
| 17529 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17530 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17531 | std::unique_ptr<HttpNetworkSession> session( |
| 17532 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17533 | |
| 17534 | // Send a simple request and make sure it goes through. |
| 17535 | HttpRequestInfo request; |
| 17536 | request.method = "GET"; |
| 17537 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17538 | request.traffic_annotation = |
| 17539 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17540 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17541 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17542 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17543 | |
| 17544 | MockWrite data_writes[] = { |
| 17545 | MockWrite("GET / HTTP/1.1\r\n" |
| 17546 | "Host: www.example.org\r\n" |
| 17547 | "Connection: keep-alive\r\n\r\n"), |
| 17548 | }; |
| 17549 | MockRead data_reads[] = { |
| 17550 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17551 | MockRead(SYNCHRONOUS, OK), |
| 17552 | }; |
| 17553 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17554 | arraysize(data_writes)); |
| 17555 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17556 | |
| 17557 | TestCompletionCallback callback; |
| 17558 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17559 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17560 | } |
| 17561 | |
| 17562 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17563 | // when the throttle is unblocked. |
| 17564 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17565 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17566 | std::unique_ptr<HttpNetworkSession> session( |
| 17567 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17568 | |
| 17569 | // Send a simple request and make sure it goes through. |
| 17570 | HttpRequestInfo request; |
| 17571 | request.method = "GET"; |
| 17572 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17573 | request.traffic_annotation = |
| 17574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17575 | |
| 17576 | MockWrite data_writes[] = { |
| 17577 | MockWrite("GET / HTTP/1.1\r\n" |
| 17578 | "Host: www.example.org\r\n" |
| 17579 | "Connection: keep-alive\r\n\r\n"), |
| 17580 | }; |
| 17581 | MockRead data_reads[] = { |
| 17582 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17583 | MockRead(SYNCHRONOUS, OK), |
| 17584 | }; |
| 17585 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17586 | arraysize(data_writes)); |
| 17587 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17588 | |
| 17589 | // Start a request that will be throttled at start; confirm it |
| 17590 | // doesn't complete. |
| 17591 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17592 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17593 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17594 | |
| 17595 | TestCompletionCallback callback; |
| 17596 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17597 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17598 | |
| 17599 | base::RunLoop().RunUntilIdle(); |
| 17600 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17601 | EXPECT_FALSE(callback.have_result()); |
| 17602 | |
| 17603 | // Confirm the request goes on to complete when unthrottled. |
| 17604 | throttler->UnthrottleAllRequests(); |
| 17605 | base::RunLoop().RunUntilIdle(); |
| 17606 | ASSERT_TRUE(callback.have_result()); |
| 17607 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17608 | } |
| 17609 | |
| 17610 | // Destroy a request while it's throttled. |
| 17611 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17612 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17613 | std::unique_ptr<HttpNetworkSession> session( |
| 17614 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17615 | |
| 17616 | // Send a simple request and make sure it goes through. |
| 17617 | HttpRequestInfo request; |
| 17618 | request.method = "GET"; |
| 17619 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17620 | request.traffic_annotation = |
| 17621 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17622 | |
| 17623 | MockWrite data_writes[] = { |
| 17624 | MockWrite("GET / HTTP/1.1\r\n" |
| 17625 | "Host: www.example.org\r\n" |
| 17626 | "Connection: keep-alive\r\n\r\n"), |
| 17627 | }; |
| 17628 | MockRead data_reads[] = { |
| 17629 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17630 | MockRead(SYNCHRONOUS, OK), |
| 17631 | }; |
| 17632 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17633 | arraysize(data_writes)); |
| 17634 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17635 | |
| 17636 | // Start a request that will be throttled at start; confirm it |
| 17637 | // doesn't complete. |
| 17638 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17639 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17640 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17641 | |
| 17642 | TestCompletionCallback callback; |
| 17643 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17644 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17645 | |
| 17646 | base::RunLoop().RunUntilIdle(); |
| 17647 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17648 | EXPECT_FALSE(callback.have_result()); |
| 17649 | |
| 17650 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17651 | trans.reset(); |
| 17652 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17653 | } |
| 17654 | |
| 17655 | // Confirm the throttler receives SetPriority calls. |
| 17656 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17657 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17658 | std::unique_ptr<HttpNetworkSession> session( |
| 17659 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17660 | |
| 17661 | // Send a simple request and make sure it goes through. |
| 17662 | HttpRequestInfo request; |
| 17663 | request.method = "GET"; |
| 17664 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17665 | request.traffic_annotation = |
| 17666 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17667 | |
| 17668 | MockWrite data_writes[] = { |
| 17669 | MockWrite("GET / HTTP/1.1\r\n" |
| 17670 | "Host: www.example.org\r\n" |
| 17671 | "Connection: keep-alive\r\n\r\n"), |
| 17672 | }; |
| 17673 | MockRead data_reads[] = { |
| 17674 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17675 | MockRead(SYNCHRONOUS, OK), |
| 17676 | }; |
| 17677 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17678 | arraysize(data_writes)); |
| 17679 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17680 | |
| 17681 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17682 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17683 | // Start the transaction to associate a throttle with it. |
| 17684 | TestCompletionCallback callback; |
| 17685 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17686 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17687 | |
| 17688 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17689 | trans->SetPriority(LOW); |
| 17690 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17691 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17692 | |
| 17693 | throttler->UnthrottleAllRequests(); |
| 17694 | base::RunLoop().RunUntilIdle(); |
| 17695 | ASSERT_TRUE(callback.have_result()); |
| 17696 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17697 | } |
| 17698 | |
| 17699 | // Confirm that unthrottling from a SetPriority call by the |
| 17700 | // throttler works properly. |
| 17701 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17702 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17703 | std::unique_ptr<HttpNetworkSession> session( |
| 17704 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17705 | |
| 17706 | // Send a simple request and make sure it goes through. |
| 17707 | HttpRequestInfo request; |
| 17708 | request.method = "GET"; |
| 17709 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17710 | request.traffic_annotation = |
| 17711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17712 | |
| 17713 | MockWrite data_writes[] = { |
| 17714 | MockWrite("GET / HTTP/1.1\r\n" |
| 17715 | "Host: www.example.org\r\n" |
| 17716 | "Connection: keep-alive\r\n\r\n"), |
| 17717 | }; |
| 17718 | MockRead data_reads[] = { |
| 17719 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17720 | MockRead(SYNCHRONOUS, OK), |
| 17721 | }; |
| 17722 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17723 | arraysize(data_writes)); |
| 17724 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17725 | |
| 17726 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17727 | data_writes, arraysize(data_writes)); |
| 17728 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17729 | |
| 17730 | // Start a request that will be throttled at start; confirm it |
| 17731 | // doesn't complete. |
| 17732 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17733 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17734 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17735 | |
| 17736 | TestCompletionCallback callback; |
| 17737 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17738 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17739 | |
| 17740 | base::RunLoop().RunUntilIdle(); |
| 17741 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17742 | EXPECT_FALSE(callback.have_result()); |
| 17743 | |
| 17744 | // Create a new request, call SetPriority on it to unthrottle, |
| 17745 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17746 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17747 | throttler->set_priority_change_closure( |
| 17748 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17749 | base::Unretained(throttler))); |
| 17750 | |
| 17751 | // Start the transaction to associate a throttle with it. |
| 17752 | TestCompletionCallback callback1; |
| 17753 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17754 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17755 | |
| 17756 | trans1->SetPriority(IDLE); |
| 17757 | |
| 17758 | base::RunLoop().RunUntilIdle(); |
| 17759 | ASSERT_TRUE(callback.have_result()); |
| 17760 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17761 | ASSERT_TRUE(callback1.have_result()); |
| 17762 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17763 | } |
| 17764 | |
| 17765 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17766 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17767 | |
| 17768 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17769 | // throttler works properly. |
| 17770 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17771 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17772 | std::unique_ptr<HttpNetworkSession> session( |
| 17773 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17774 | |
| 17775 | // Send a simple request and make sure it goes through. |
| 17776 | HttpRequestInfo request; |
| 17777 | request.method = "GET"; |
| 17778 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17779 | request.traffic_annotation = |
| 17780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17781 | |
| 17782 | MockWrite data_writes[] = { |
| 17783 | MockWrite("GET / HTTP/1.1\r\n" |
| 17784 | "Host: www.example.org\r\n" |
| 17785 | "Connection: keep-alive\r\n\r\n"), |
| 17786 | }; |
| 17787 | MockRead data_reads[] = { |
| 17788 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17789 | MockRead(SYNCHRONOUS, OK), |
| 17790 | }; |
| 17791 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17792 | arraysize(data_writes)); |
| 17793 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17794 | |
| 17795 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17796 | data_writes, arraysize(data_writes)); |
| 17797 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17798 | |
| 17799 | // Start a request that will be throttled at start; confirm it |
| 17800 | // doesn't complete. |
| 17801 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17802 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17803 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17804 | |
| 17805 | TestCompletionCallback callback; |
| 17806 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17807 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17808 | |
| 17809 | base::RunLoop().RunUntilIdle(); |
| 17810 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17811 | EXPECT_FALSE(callback.have_result()); |
| 17812 | |
| 17813 | // Arrange for the set priority call on the above transaction to delete |
| 17814 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17815 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17816 | throttler->set_priority_change_closure( |
| 17817 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17818 | |
| 17819 | // Call it and check results (partially a "doesn't crash" test). |
| 17820 | trans_ptr->SetPriority(IDLE); |
| 17821 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17822 | |
| 17823 | base::RunLoop().RunUntilIdle(); |
| 17824 | ASSERT_FALSE(callback.have_result()); |
| 17825 | } |
| 17826 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17827 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17828 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17829 | const std::string https_url = "https://www.example.com"; |
| 17830 | HttpRequestInfo request; |
| 17831 | request.url = GURL(https_url); |
| 17832 | request.method = "GET"; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17833 | request.traffic_annotation = |
| 17834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17835 | |
| 17836 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17837 | ssl.ssl_info.token_binding_negotiated = true; |
| 17838 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17839 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17840 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17841 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17842 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17843 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17844 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17845 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17846 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17848 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17849 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17851 | |
| 17852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17853 | TestCompletionCallback callback; |
| 17854 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17855 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17856 | |
| 17857 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17858 | |
| 17859 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17860 | HttpRequestHeaders headers; |
| 17861 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17862 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17863 | } |
| 17864 | #endif // !defined(OS_IOS) |
| 17865 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17866 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17867 | const std::string& accept_encoding, |
| 17868 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17869 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17870 | bool should_match) { |
| 17871 | HttpRequestInfo request; |
| 17872 | request.method = "GET"; |
| 17873 | request.url = GURL("http://www.foo.com/"); |
| 17874 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17875 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17876 | request.traffic_annotation = |
| 17877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17878 | |
| 17879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17881 | // Send headers successfully, but get an error while sending the body. |
| 17882 | MockWrite data_writes[] = { |
| 17883 | MockWrite("GET / HTTP/1.1\r\n" |
| 17884 | "Host: www.foo.com\r\n" |
| 17885 | "Connection: keep-alive\r\n" |
| 17886 | "Accept-Encoding: "), |
| 17887 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17888 | }; |
| 17889 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17890 | std::string response_code = "200 OK"; |
| 17891 | std::string extra; |
| 17892 | if (!location.empty()) { |
| 17893 | response_code = "301 Redirect\r\nLocation: "; |
| 17894 | response_code.append(location); |
| 17895 | } |
| 17896 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17897 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17898 | MockRead("HTTP/1.0 "), |
| 17899 | MockRead(response_code.data()), |
| 17900 | MockRead("\r\nContent-Encoding: "), |
| 17901 | MockRead(content_encoding.data()), |
| 17902 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17903 | MockRead(SYNCHRONOUS, OK), |
| 17904 | }; |
| 17905 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17906 | arraysize(data_writes)); |
| 17907 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17908 | |
| 17909 | TestCompletionCallback callback; |
| 17910 | |
| 17911 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17913 | |
| 17914 | rv = callback.WaitForResult(); |
| 17915 | if (should_match) { |
| 17916 | EXPECT_THAT(rv, IsOk()); |
| 17917 | } else { |
| 17918 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17919 | } |
| 17920 | } |
| 17921 | |
| 17922 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17923 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17924 | } |
| 17925 | |
| 17926 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17927 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17928 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17929 | } |
| 17930 | |
| 17931 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17932 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17933 | "", false); |
| 17934 | } |
| 17935 | |
| 17936 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17937 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17938 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17939 | } |
| 17940 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17941 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17942 | ProxyConfig proxy_config; |
| 17943 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17944 | proxy_config.set_pac_mandatory(true); |
| 17945 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17946 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17947 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17948 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17949 | |
| 17950 | HttpRequestInfo request; |
| 17951 | request.method = "GET"; |
| 17952 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17953 | request.traffic_annotation = |
| 17954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17955 | |
| 17956 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17958 | |
| 17959 | TestCompletionCallback callback; |
| 17960 | |
| 17961 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17963 | EXPECT_THAT(callback.WaitForResult(), |
| 17964 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17965 | } |
| 17966 | |
| 17967 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17968 | ProxyConfig proxy_config; |
| 17969 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17970 | proxy_config.set_pac_mandatory(true); |
| 17971 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17972 | new MockAsyncProxyResolverFactory(false); |
| 17973 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17974 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
| 17975 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 17976 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17977 | HttpRequestInfo request; |
| 17978 | request.method = "GET"; |
| 17979 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17980 | request.traffic_annotation = |
| 17981 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17982 | |
| 17983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17984 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17985 | |
| 17986 | TestCompletionCallback callback; |
| 17987 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17989 | |
| 17990 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17991 | ERR_FAILED, &resolver); |
| 17992 | EXPECT_THAT(callback.WaitForResult(), |
| 17993 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17994 | } |
| 17995 | |
| 17996 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17997 | session_deps_.proxy_resolution_service = |
| 17998 | ProxyResolutionService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17999 | session_deps_.enable_quic = false; |
| 18000 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18001 | |
| 18002 | HttpRequestInfo request; |
| 18003 | request.method = "GET"; |
| 18004 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18005 | request.traffic_annotation = |
| 18006 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18007 | |
| 18008 | TestCompletionCallback callback; |
| 18009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18010 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18011 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18012 | |
| 18013 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18014 | } |
| 18015 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 18016 | } // namespace net |