[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" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 28 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 40 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 41 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 42 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 43 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 44 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 45 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 46 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 47 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 48 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 49 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 50 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 54 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 55 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 57 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 58 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 59 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 60 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 61 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 62 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 70 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 71 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 72 | #include "net/proxy_resolution/proxy_info.h" |
| 73 | #include "net/proxy_resolution/proxy_resolver.h" |
| 74 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
| 75 | #include "net/proxy_resolution/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 76 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 77 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 79 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 80 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 81 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 82 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 83 | #include "net/socket/socket_test_util.h" |
| 84 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 85 | #include "net/spdy/chromium/spdy_session.h" |
| 86 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 87 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 88 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 89 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 90 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 91 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service_defaults.h" |
| 93 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 94 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 95 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 96 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 97 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 98 | #include "net/test/test_data_directory.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 99 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 100 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 101 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 102 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 103 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 104 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 105 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 106 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 107 | #if defined(NTLM_PORTABLE) |
| 108 | #include "base/base64.h" |
| 109 | #include "net/ntlm/ntlm_test_data.h" |
| 110 | #endif |
| 111 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 112 | using net::test::IsError; |
| 113 | using net::test::IsOk; |
| 114 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 115 | using base::ASCIIToUTF16; |
| 116 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 117 | //----------------------------------------------------------------------------- |
| 118 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 119 | namespace net { |
| 120 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 121 | namespace { |
| 122 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 123 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 124 | public: |
| 125 | TestNetworkStreamThrottler() |
| 126 | : throttle_new_requests_(false), |
| 127 | num_set_priority_calls_(0), |
| 128 | last_priority_set_(IDLE) {} |
| 129 | |
| 130 | ~TestNetworkStreamThrottler() override { |
| 131 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 132 | } |
| 133 | |
| 134 | // NetworkThrottleManager |
| 135 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 136 | RequestPriority priority, |
| 137 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 138 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 139 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 140 | outstanding_throttles_.insert(test_throttle.get()); |
| 141 | return std::move(test_throttle); |
| 142 | } |
| 143 | |
| 144 | void UnthrottleAllRequests() { |
| 145 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 146 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 147 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 148 | throttle->Unthrottle(); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 153 | throttle_new_requests_ = throttle_new_requests; |
| 154 | } |
| 155 | |
| 156 | // Includes both throttled and unthrottled throttles. |
| 157 | size_t num_outstanding_requests() const { |
| 158 | return outstanding_throttles_.size(); |
| 159 | } |
| 160 | |
| 161 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 162 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 163 | void set_priority_change_closure( |
| 164 | const base::Closure& priority_change_closure) { |
| 165 | priority_change_closure_ = priority_change_closure; |
| 166 | } |
| 167 | |
| 168 | private: |
| 169 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 170 | public: |
| 171 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 172 | |
| 173 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 174 | bool IsBlocked() const override { return throttled_; } |
| 175 | RequestPriority Priority() const override { |
| 176 | NOTREACHED(); |
| 177 | return IDLE; |
| 178 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 179 | void SetPriority(RequestPriority priority) override { |
| 180 | throttler_->SetPriorityCalled(priority); |
| 181 | } |
| 182 | |
| 183 | TestThrottle(bool throttled, |
| 184 | ThrottleDelegate* delegate, |
| 185 | TestNetworkStreamThrottler* throttler) |
| 186 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 187 | |
| 188 | void Unthrottle() { |
| 189 | EXPECT_TRUE(throttled_); |
| 190 | |
| 191 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 192 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | bool throttled_; |
| 196 | ThrottleDelegate* delegate_; |
| 197 | TestNetworkStreamThrottler* throttler_; |
| 198 | }; |
| 199 | |
| 200 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 201 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 202 | outstanding_throttles_.erase(throttle); |
| 203 | } |
| 204 | |
| 205 | void SetPriorityCalled(RequestPriority priority) { |
| 206 | ++num_set_priority_calls_; |
| 207 | last_priority_set_ = priority; |
| 208 | if (!priority_change_closure_.is_null()) |
| 209 | priority_change_closure_.Run(); |
| 210 | } |
| 211 | |
| 212 | // Includes both throttled and unthrottled throttles. |
| 213 | std::set<TestThrottle*> outstanding_throttles_; |
| 214 | bool throttle_new_requests_; |
| 215 | int num_set_priority_calls_; |
| 216 | RequestPriority last_priority_set_; |
| 217 | base::Closure priority_change_closure_; |
| 218 | |
| 219 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 220 | }; |
| 221 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 222 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 223 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 224 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 225 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 226 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 227 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 228 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 229 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 230 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 231 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 232 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 233 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 234 | const char kAlternativeServiceHttpHeader[] = |
| 235 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 236 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 237 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 238 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 239 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 240 | } |
| 241 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 242 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 243 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 244 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 245 | } |
| 246 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 247 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 248 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 249 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 250 | } |
| 251 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 252 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 253 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 254 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 255 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 256 | if (!params) |
| 257 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 258 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 259 | if (!params->GetList("headers", &header_list)) |
| 260 | return false; |
| 261 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 262 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 263 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 264 | return true; |
| 265 | } |
| 266 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 267 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 268 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 269 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 270 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 271 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 272 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 273 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 274 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 275 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 276 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 277 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 278 | |
| 279 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 280 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 281 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 282 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 283 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 284 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 285 | } |
| 286 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 287 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 288 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 289 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 290 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 291 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 292 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | |
| 294 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 295 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 296 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 297 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 298 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 299 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 300 | load_timing_info.send_start); |
| 301 | |
| 302 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 303 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 304 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 305 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 306 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 307 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 311 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 312 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 313 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 314 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 315 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 316 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 317 | |
| 318 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 319 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 320 | load_timing_info.proxy_resolve_end); |
| 321 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 322 | load_timing_info.send_start); |
| 323 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 324 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 325 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 326 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 327 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 328 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 332 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 333 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 334 | int connect_timing_flags) { |
| 335 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 336 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 337 | |
| 338 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 339 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 340 | load_timing_info.proxy_resolve_end); |
| 341 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 342 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 343 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 344 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 345 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 346 | load_timing_info.send_start); |
| 347 | |
| 348 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 349 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 350 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 351 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 352 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 353 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 354 | } |
| 355 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 356 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 357 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 358 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 359 | } |
| 360 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 361 | // Note that the pointer written into |*throttler| will only be valid |
| 362 | // for the lifetime of the returned HttpNetworkSession. |
| 363 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 364 | SpdySessionDependencies* session_deps, |
| 365 | TestNetworkStreamThrottler** throttler) { |
| 366 | std::unique_ptr<HttpNetworkSession> session( |
| 367 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 368 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 369 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 370 | *throttler = owned_throttler.get(); |
| 371 | |
| 372 | HttpNetworkSessionPeer peer(session.get()); |
| 373 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 374 | |
| 375 | return session; |
| 376 | } |
| 377 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 378 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 379 | public: |
| 380 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 381 | |
| 382 | // ProxyResolverFactory override. |
| 383 | int CreateProxyResolver( |
| 384 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 385 | std::unique_ptr<ProxyResolver>* result, |
| 386 | const CompletionCallback& callback, |
| 387 | std::unique_ptr<Request>* request) override { |
| 388 | return ERR_PAC_SCRIPT_FAILED; |
| 389 | } |
| 390 | }; |
| 391 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 392 | } // namespace |
| 393 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 394 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 395 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 396 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 397 | // Important to restore the per-pool limit first, since the pool limit must |
| 398 | // always be greater than group limit, and the tests reduce both limits. |
| 399 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 400 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 401 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 402 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 403 | } |
| 404 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 405 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 406 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 407 | : ssl_(ASYNC, OK), |
| 408 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 409 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 410 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 411 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 412 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 413 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 414 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 415 | struct SimpleGetHelperResult { |
| 416 | int rv; |
| 417 | std::string status_line; |
| 418 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 419 | int64_t total_received_bytes; |
| 420 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 421 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 422 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 423 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 424 | }; |
| 425 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 426 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 427 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 428 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 429 | } |
| 430 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 431 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 432 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 433 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 434 | // Empty the current queue. |
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 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 437 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 438 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 439 | } |
| 440 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 441 | // Either |write_failure| specifies a write failure or |read_failure| |
| 442 | // specifies a read failure when using a reused socket. In either case, the |
| 443 | // failure should cause the network transaction to resend the request, and the |
| 444 | // other argument should be NULL. |
| 445 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 446 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 447 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 448 | // Either |write_failure| specifies a write failure or |read_failure| |
| 449 | // specifies a read failure when using a reused socket. In either case, the |
| 450 | // failure should cause the network transaction to resend the request, and the |
| 451 | // other argument should be NULL. |
| 452 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 453 | const MockRead* read_failure, |
| 454 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 455 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 456 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 457 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 458 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 459 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | HttpRequestInfo request; |
| 461 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 462 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 463 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 464 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 465 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 468 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 469 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 470 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 471 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 473 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 475 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 476 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 478 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 479 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 480 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 481 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 482 | |
| 483 | // Even in the failure cases that use this function, connections are always |
| 484 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 485 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 486 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 487 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 488 | if (out.rv != OK) |
| 489 | return out; |
| 490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 491 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 492 | // Can't use ASSERT_* inside helper functions like this, so |
| 493 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 494 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 495 | out.rv = ERR_UNEXPECTED; |
| 496 | return out; |
| 497 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 498 | out.status_line = response->headers->GetStatusLine(); |
| 499 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 500 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 501 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 502 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 503 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 505 | EXPECT_EQ(got_endpoint, |
| 506 | out.remote_endpoint_after_start.address().size() > 0); |
| 507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 508 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 510 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 511 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 512 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 513 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 514 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 515 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 516 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 517 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 518 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 519 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 520 | std::string line; |
| 521 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 522 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 523 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 524 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 525 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 526 | std::string value; |
| 527 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 528 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 529 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 530 | EXPECT_EQ("keep-alive", value); |
| 531 | |
| 532 | std::string response_headers; |
| 533 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 534 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 535 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 537 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 538 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 539 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 541 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 542 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 543 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 544 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 545 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 546 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | MockWrite data_writes[] = { |
| 548 | MockWrite("GET / HTTP/1.1\r\n" |
| 549 | "Host: www.example.org\r\n" |
| 550 | "Connection: keep-alive\r\n\r\n"), |
| 551 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 552 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 553 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 554 | arraysize(data_writes)); |
| 555 | StaticSocketDataProvider* data[] = {&reads}; |
| 556 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 557 | |
| 558 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 559 | out.total_sent_bytes); |
| 560 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 561 | } |
| 562 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 563 | void AddSSLSocketData() { |
| 564 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 565 | ssl_.ssl_info.cert = |
| 566 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 567 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 569 | } |
| 570 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 571 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 572 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 573 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 574 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 575 | |
| 576 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 577 | |
| 578 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 579 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 580 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 581 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 582 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 583 | |
| 584 | // Original socket limits. Some tests set these. Safest to always restore |
| 585 | // them once each test has been run. |
| 586 | int old_max_group_sockets_; |
| 587 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 588 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 589 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 590 | namespace { |
| 591 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 592 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 593 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 594 | BeforeHeadersSentHandler() |
| 595 | : observed_before_headers_sent_with_proxy_(false), |
| 596 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 597 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 599 | HttpRequestHeaders* request_headers) { |
| 600 | observed_before_headers_sent_ = true; |
| 601 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 602 | !proxy_info.is_quic()) { |
| 603 | return; |
| 604 | } |
| 605 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 606 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 607 | } |
| 608 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 609 | bool observed_before_headers_sent_with_proxy() const { |
| 610 | return observed_before_headers_sent_with_proxy_; |
| 611 | } |
| 612 | |
| 613 | bool observed_before_headers_sent() const { |
| 614 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | std::string observed_proxy_server_uri() const { |
| 618 | return observed_proxy_server_uri_; |
| 619 | } |
| 620 | |
| 621 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 622 | bool observed_before_headers_sent_with_proxy_; |
| 623 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 624 | std::string observed_proxy_server_uri_; |
| 625 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 626 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 627 | }; |
| 628 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 629 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 630 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 631 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 632 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 633 | const int sizeof_row = strlen(row); |
| 634 | const int num_rows = static_cast<int>( |
| 635 | ceil(static_cast<float>(size) / sizeof_row)); |
| 636 | const int sizeof_data = num_rows * sizeof_row; |
| 637 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 638 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 639 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 640 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 641 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 642 | } |
| 643 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 644 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 645 | uint64_t MockGetMSTime() { |
| 646 | // Tue, 23 May 2017 20:13:07 +0000 |
| 647 | return 131400439870000000; |
| 648 | } |
| 649 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 650 | // Alternative functions that eliminate randomness and dependency on the local |
| 651 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 652 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 653 | // This is set to 0xaa because the client challenge for testing in |
| 654 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 655 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 658 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 659 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 660 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 661 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 662 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 663 | template<typename ParentPool> |
| 664 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 665 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 666 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 667 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 668 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 669 | const std::string last_group_name_received() const { |
| 670 | return last_group_name_; |
| 671 | } |
| 672 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 673 | bool socket_requested() const { return socket_requested_; } |
| 674 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 675 | int RequestSocket(const std::string& group_name, |
| 676 | const void* socket_params, |
| 677 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 678 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 679 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 680 | ClientSocketHandle* handle, |
| 681 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 682 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 683 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 684 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 685 | return ERR_IO_PENDING; |
| 686 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 687 | void CancelRequest(const std::string& group_name, |
| 688 | ClientSocketHandle* handle) override {} |
| 689 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 690 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 691 | int id) override {} |
| 692 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 693 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 694 | int IdleSocketCount() const override { return 0; } |
| 695 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 696 | return 0; |
| 697 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 698 | LoadState GetLoadState(const std::string& group_name, |
| 699 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 700 | return LOAD_STATE_IDLE; |
| 701 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 702 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 703 | return base::TimeDelta(); |
| 704 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 705 | |
| 706 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 707 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 708 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 709 | }; |
| 710 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 711 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 712 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 713 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 714 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 715 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 716 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 717 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 718 | CaptureGroupNameSSLSocketPool; |
| 719 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 720 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 721 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 722 | HostResolver* host_resolver, |
| 723 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 724 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 725 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 726 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 727 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 728 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 729 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 730 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 731 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 732 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 733 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 734 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 735 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 736 | : SSLClientSocketPool(0, |
| 737 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 738 | cert_verifier, |
| 739 | NULL, |
| 740 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 741 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 742 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 743 | std::string(), |
| 744 | NULL, |
| 745 | NULL, |
| 746 | NULL, |
| 747 | NULL, |
| 748 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 749 | NULL) { |
| 750 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 751 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 752 | //----------------------------------------------------------------------------- |
| 753 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 754 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 755 | // configured for common cases. |
| 756 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 757 | if (!auth_challenge) |
| 758 | return false; |
| 759 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 760 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 762 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | return true; |
| 764 | } |
| 765 | |
| 766 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 767 | if (!auth_challenge) |
| 768 | return false; |
| 769 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 770 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 771 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 772 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 773 | return true; |
| 774 | } |
| 775 | |
| 776 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 777 | if (!auth_challenge) |
| 778 | return false; |
| 779 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 780 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 781 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 782 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 783 | return true; |
| 784 | } |
| 785 | |
| 786 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 787 | if (!auth_challenge) |
| 788 | return false; |
| 789 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 790 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 791 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 792 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 793 | return true; |
| 794 | } |
| 795 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 796 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 797 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 798 | if (!auth_challenge) |
| 799 | return false; |
| 800 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 801 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 802 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 803 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 804 | return true; |
| 805 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 806 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 807 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 808 | } // namespace |
| 809 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 810 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 813 | } |
| 814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 815 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 817 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 818 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 819 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 820 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 821 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 822 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 823 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 824 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 825 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 826 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 827 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 828 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 829 | |
| 830 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 831 | } |
| 832 | |
| 833 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 834 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 835 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 836 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 837 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 838 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 839 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 840 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 841 | EXPECT_THAT(out.rv, IsOk()); |
| 842 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 843 | EXPECT_EQ("hello world", out.response_data); |
| 844 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 845 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 846 | } |
| 847 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 848 | // Response with no status line, and a weird port. Should fail by default. |
| 849 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 850 | MockRead data_reads[] = { |
| 851 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 852 | }; |
| 853 | |
| 854 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 856 | |
| 857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 858 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 859 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 860 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 861 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 862 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 863 | request.method = "GET"; |
| 864 | request.url = GURL("http://www.example.com:2000/"); |
| 865 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 866 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 867 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 868 | } |
| 869 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 870 | // Tests that request info can be destroyed after the headers phase is complete. |
| 871 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 872 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 873 | auto trans = |
| 874 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 875 | |
| 876 | MockRead data_reads[] = { |
| 877 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 878 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 879 | }; |
| 880 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 881 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 882 | |
| 883 | TestCompletionCallback callback; |
| 884 | |
| 885 | { |
| 886 | auto request = std::make_unique<HttpRequestInfo>(); |
| 887 | request->method = "GET"; |
| 888 | request->url = GURL("http://www.example.org/"); |
| 889 | |
| 890 | int rv = |
| 891 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 892 | |
| 893 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 894 | } // Let request info be destroyed. |
| 895 | |
| 896 | trans.reset(); |
| 897 | } |
| 898 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 899 | // Response with no status line, and a weird port. Option to allow weird ports |
| 900 | // enabled. |
| 901 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 902 | MockRead data_reads[] = { |
| 903 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 904 | }; |
| 905 | |
| 906 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 908 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 910 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 911 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 912 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 913 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 914 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 915 | request.method = "GET"; |
| 916 | request.url = GURL("http://www.example.com:2000/"); |
| 917 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 918 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 919 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 920 | |
| 921 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 922 | ASSERT_TRUE(info->headers); |
| 923 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 924 | |
| 925 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 926 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 927 | } |
| 928 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 929 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 930 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 931 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 932 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 933 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 935 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 936 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 937 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 939 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 940 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 941 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 945 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 946 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 947 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 948 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 950 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 951 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 952 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 954 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 955 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 956 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 960 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 961 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 962 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 963 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 964 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 965 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 966 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 967 | EXPECT_THAT(out.rv, IsOk()); |
| 968 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 969 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 970 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 971 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 975 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 976 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 977 | MockRead("\n"), |
| 978 | MockRead("\n"), |
| 979 | MockRead("Q"), |
| 980 | MockRead("J"), |
| 981 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 982 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 983 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 984 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 985 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 986 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 987 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 988 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 989 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 990 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 995 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 996 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 997 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 998 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 999 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1000 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1001 | EXPECT_THAT(out.rv, IsOk()); |
| 1002 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1003 | EXPECT_EQ("HTT", out.response_data); |
| 1004 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1005 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1006 | } |
| 1007 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1008 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1009 | // persistent connection. The response should still terminate since a 204 |
| 1010 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1011 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1012 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1013 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1014 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1015 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1016 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1017 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1018 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1019 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1020 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1021 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1022 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1023 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1024 | int64_t response_size = reads_size - strlen(junk); |
| 1025 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1026 | } |
| 1027 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1028 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1029 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1030 | std::string final_chunk = "0\r\n\r\n"; |
| 1031 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1032 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1033 | MockRead data_reads[] = { |
| 1034 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1035 | MockRead("5\r\nHello\r\n"), |
| 1036 | MockRead("1\r\n"), |
| 1037 | MockRead(" \r\n"), |
| 1038 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1039 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1040 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1041 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1042 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1043 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1044 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1045 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1046 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1047 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1048 | int64_t response_size = reads_size - extra_data.size(); |
| 1049 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1050 | } |
| 1051 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1052 | // Next tests deal with http://crbug.com/56344. |
| 1053 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1054 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1055 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1056 | MockRead data_reads[] = { |
| 1057 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1058 | MockRead("Content-Length: 10\r\n"), |
| 1059 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1060 | }; |
| 1061 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1062 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1063 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1064 | } |
| 1065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1066 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1067 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1068 | MockRead data_reads[] = { |
| 1069 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1070 | MockRead("Content-Length: 5\r\n"), |
| 1071 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1072 | MockRead("Hello"), |
| 1073 | }; |
| 1074 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1075 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1076 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1077 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1078 | EXPECT_EQ("Hello", out.response_data); |
| 1079 | } |
| 1080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1081 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1082 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1083 | // More than 2 dupes. |
| 1084 | { |
| 1085 | MockRead data_reads[] = { |
| 1086 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1087 | MockRead("Content-Length: 5\r\n"), |
| 1088 | MockRead("Content-Length: 5\r\n"), |
| 1089 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1090 | MockRead("Hello"), |
| 1091 | }; |
| 1092 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1093 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1094 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1095 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1096 | EXPECT_EQ("Hello", out.response_data); |
| 1097 | } |
| 1098 | // HTTP/1.0 |
| 1099 | { |
| 1100 | MockRead data_reads[] = { |
| 1101 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1102 | MockRead("Content-Length: 5\r\n"), |
| 1103 | MockRead("Content-Length: 5\r\n"), |
| 1104 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1105 | MockRead("Hello"), |
| 1106 | }; |
| 1107 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1108 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1109 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1110 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1111 | EXPECT_EQ("Hello", out.response_data); |
| 1112 | } |
| 1113 | // 2 dupes and one mismatched. |
| 1114 | { |
| 1115 | MockRead data_reads[] = { |
| 1116 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1117 | MockRead("Content-Length: 10\r\n"), |
| 1118 | MockRead("Content-Length: 10\r\n"), |
| 1119 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1120 | }; |
| 1121 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1122 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1123 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1124 | } |
| 1125 | } |
| 1126 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1127 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1128 | MultipleContentLengthHeadersTransferEncoding) { |
| 1129 | MockRead data_reads[] = { |
| 1130 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1131 | MockRead("Content-Length: 666\r\n"), |
| 1132 | MockRead("Content-Length: 1337\r\n"), |
| 1133 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1134 | MockRead("5\r\nHello\r\n"), |
| 1135 | MockRead("1\r\n"), |
| 1136 | MockRead(" \r\n"), |
| 1137 | MockRead("5\r\nworld\r\n"), |
| 1138 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1139 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1140 | }; |
| 1141 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1142 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1143 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1144 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1145 | EXPECT_EQ("Hello world", out.response_data); |
| 1146 | } |
| 1147 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1148 | // Next tests deal with http://crbug.com/98895. |
| 1149 | |
| 1150 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1151 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | MockRead data_reads[] = { |
| 1153 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1154 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1155 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1156 | MockRead("Hello"), |
| 1157 | }; |
| 1158 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1159 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1160 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1162 | EXPECT_EQ("Hello", out.response_data); |
| 1163 | } |
| 1164 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1165 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1166 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | MockRead data_reads[] = { |
| 1168 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1169 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1170 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1171 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1172 | MockRead("Hello"), |
| 1173 | }; |
| 1174 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1175 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1176 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1177 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1178 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1182 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | MockRead data_reads[] = { |
| 1184 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1185 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1186 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1187 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1188 | MockRead("Hello"), |
| 1189 | }; |
| 1190 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1191 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1192 | EXPECT_THAT(out.rv, |
| 1193 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | } |
| 1195 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1196 | // Checks that two identical Location headers result in no error. |
| 1197 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1198 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | MockRead data_reads[] = { |
| 1200 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1201 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1202 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1203 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | }; |
| 1206 | |
| 1207 | HttpRequestInfo request; |
| 1208 | request.method = "GET"; |
| 1209 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1213 | |
| 1214 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1217 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1218 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1219 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1221 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1222 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1224 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1225 | ASSERT_TRUE(response); |
| 1226 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1227 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1228 | std::string url; |
| 1229 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1230 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1231 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1232 | } |
| 1233 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1234 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1235 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1236 | MockRead data_reads[] = { |
| 1237 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1238 | MockRead("Location: http://good.com/\r\n"), |
| 1239 | MockRead("Location: http://evil.com/\r\n"), |
| 1240 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1242 | }; |
| 1243 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1244 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1245 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1246 | } |
| 1247 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1249 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1250 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1251 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1253 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1255 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1256 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1257 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1258 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1259 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1260 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1261 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1262 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1263 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1264 | "Host: www.example.org\r\n" |
| 1265 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | }; |
| 1267 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1268 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1269 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1270 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1271 | // No response body because the test stops reading here. |
| 1272 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1273 | }; |
| 1274 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1275 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1276 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1277 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1278 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1279 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1281 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1283 | |
| 1284 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1287 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1288 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1289 | |
| 1290 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1291 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1292 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1293 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1294 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1295 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1296 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1297 | |
| 1298 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1299 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1300 | bool has_server_header = response->headers->EnumerateHeader( |
| 1301 | &iter, "Server", &server_header); |
| 1302 | EXPECT_TRUE(has_server_header); |
| 1303 | EXPECT_EQ("Blah", server_header); |
| 1304 | |
| 1305 | // Reading should give EOF right away, since there is no message body |
| 1306 | // (despite non-zero content-length). |
| 1307 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1308 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1309 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1310 | EXPECT_EQ("", response_data); |
| 1311 | } |
| 1312 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1313 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1314 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
| 1316 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1317 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1318 | MockRead("hello"), |
| 1319 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1320 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1321 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1323 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1326 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | "hello", "world" |
| 1328 | }; |
| 1329 | |
| 1330 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1331 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1333 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1335 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1337 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1339 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | |
| 1342 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1343 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1345 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1346 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1348 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1349 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1350 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1351 | |
| 1352 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1355 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | } |
| 1357 | } |
| 1358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1359 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1360 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1361 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1362 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1363 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1364 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1365 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | request.method = "POST"; |
| 1367 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1368 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1370 | // Check the upload progress returned before initialization is correct. |
| 1371 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1372 | EXPECT_EQ(0u, progress.size()); |
| 1373 | EXPECT_EQ(0u, progress.position()); |
| 1374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1377 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1379 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1380 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1381 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1382 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1384 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1385 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1387 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1388 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1391 | |
| 1392 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1395 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1396 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1397 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1398 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1399 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | |
| 1401 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1402 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1404 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1405 | } |
| 1406 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1407 | // This test is almost the same as Ignores100 above, but the response contains |
| 1408 | // 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] | 1409 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1410 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1411 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1412 | request.method = "GET"; |
| 1413 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1416 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1417 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1418 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1419 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1420 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1421 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1423 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1427 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1429 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1431 | |
| 1432 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1435 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1436 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1437 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1438 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1439 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1440 | |
| 1441 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1442 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1444 | EXPECT_EQ("hello world", response_data); |
| 1445 | } |
| 1446 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1447 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1448 | HttpRequestInfo request; |
| 1449 | request.method = "POST"; |
| 1450 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1451 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1452 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1453 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1454 | |
| 1455 | MockRead data_reads[] = { |
| 1456 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1457 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1458 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1460 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1461 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1462 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1463 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1464 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1466 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1467 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1468 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1469 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1470 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1471 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1472 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1473 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1474 | } |
| 1475 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1476 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1477 | HttpRequestInfo request; |
| 1478 | request.method = "POST"; |
| 1479 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1483 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1484 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1485 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1486 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1487 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1490 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1491 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1492 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1494 | |
| 1495 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1496 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1497 | } |
| 1498 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1499 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1500 | const MockWrite* write_failure, |
| 1501 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1502 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1503 | request.method = "GET"; |
| 1504 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1505 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1506 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1507 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1509 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1510 | // Written data for successfully sending both requests. |
| 1511 | MockWrite data1_writes[] = { |
| 1512 | MockWrite("GET / HTTP/1.1\r\n" |
| 1513 | "Host: www.foo.com\r\n" |
| 1514 | "Connection: keep-alive\r\n\r\n"), |
| 1515 | MockWrite("GET / HTTP/1.1\r\n" |
| 1516 | "Host: www.foo.com\r\n" |
| 1517 | "Connection: keep-alive\r\n\r\n") |
| 1518 | }; |
| 1519 | |
| 1520 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1521 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1522 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1523 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1524 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1525 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1526 | |
| 1527 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1528 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1529 | data1_writes[1] = *write_failure; |
| 1530 | } else { |
| 1531 | ASSERT_TRUE(read_failure); |
| 1532 | data1_reads[2] = *read_failure; |
| 1533 | } |
| 1534 | |
| 1535 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1536 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1537 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1538 | |
| 1539 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1540 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1541 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1542 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1543 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1544 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1545 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1546 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1547 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1548 | "hello", "world" |
| 1549 | }; |
| 1550 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1551 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1552 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1553 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1556 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1557 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1559 | |
| 1560 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1561 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1562 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1563 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1564 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1565 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1566 | if (i == 0) { |
| 1567 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1568 | } else { |
| 1569 | // The second request should be using a new socket. |
| 1570 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1571 | } |
| 1572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1574 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1575 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1576 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1577 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1578 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1579 | |
| 1580 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1581 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1582 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1583 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1584 | } |
| 1585 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1588 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1589 | const MockRead* read_failure, |
| 1590 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1591 | HttpRequestInfo request; |
| 1592 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1593 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1594 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1595 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1596 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1598 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1599 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1600 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1601 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1602 | ssl1.next_proto = kProtoHTTP2; |
| 1603 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1604 | } |
| 1605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1607 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1608 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1609 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1610 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1611 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1612 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1613 | SpdySerializedFrame spdy_data( |
| 1614 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1615 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1616 | // HTTP/1.1 versions of the request and response. |
| 1617 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1618 | "Host: www.foo.com\r\n" |
| 1619 | "Connection: keep-alive\r\n\r\n"; |
| 1620 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1621 | const char kHttpData[] = "hello"; |
| 1622 | |
| 1623 | std::vector<MockRead> data1_reads; |
| 1624 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1625 | if (write_failure) { |
| 1626 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1627 | data1_writes.push_back(*write_failure); |
| 1628 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1629 | } else { |
| 1630 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1631 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1632 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1633 | } else { |
| 1634 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1635 | } |
| 1636 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1637 | } |
| 1638 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1639 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1640 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1641 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1642 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1643 | std::vector<MockRead> data2_reads; |
| 1644 | std::vector<MockWrite> data2_writes; |
| 1645 | |
| 1646 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1647 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1648 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1649 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1650 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1651 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1652 | } else { |
| 1653 | data2_writes.push_back( |
| 1654 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1655 | |
| 1656 | data2_reads.push_back( |
| 1657 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1658 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1659 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1660 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1661 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1662 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1663 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1664 | |
| 1665 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1666 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1667 | // Wait for the preconnect to complete. |
| 1668 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1669 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1670 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1671 | |
| 1672 | // Make the request. |
| 1673 | TestCompletionCallback callback; |
| 1674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1676 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1677 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1679 | |
| 1680 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1681 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1682 | |
| 1683 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1684 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1685 | TestLoadTimingNotReused( |
| 1686 | load_timing_info, |
| 1687 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1689 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1690 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1691 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1692 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1693 | if (response->was_fetched_via_spdy) { |
| 1694 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1695 | } else { |
| 1696 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1697 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1698 | |
| 1699 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1700 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1702 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1703 | } |
| 1704 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1705 | // Test that we do not retry indefinitely when a server sends an error like |
| 1706 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1707 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1708 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1709 | HttpRequestInfo request; |
| 1710 | request.method = "GET"; |
| 1711 | request.url = GURL("https://www.foo.com/"); |
| 1712 | |
| 1713 | // Check whether we give up after the third try. |
| 1714 | |
| 1715 | // Construct an HTTP2 request and a "Go away" response. |
| 1716 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1717 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1718 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1719 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1720 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1721 | |
| 1722 | // Three go away responses. |
| 1723 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1724 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1725 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1726 | |
| 1727 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1728 | AddSSLSocketData(); |
| 1729 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1730 | AddSSLSocketData(); |
| 1731 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1732 | AddSSLSocketData(); |
| 1733 | |
| 1734 | TestCompletionCallback callback; |
| 1735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1737 | |
| 1738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1740 | |
| 1741 | rv = callback.WaitForResult(); |
| 1742 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1743 | } |
| 1744 | |
| 1745 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1746 | HttpRequestInfo request; |
| 1747 | request.method = "GET"; |
| 1748 | request.url = GURL("https://www.foo.com/"); |
| 1749 | |
| 1750 | // Check whether we try atleast thrice before giving up. |
| 1751 | |
| 1752 | // Construct an HTTP2 request and a "Go away" response. |
| 1753 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1754 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1755 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1756 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1757 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1758 | |
| 1759 | // Construct a non error HTTP2 response. |
| 1760 | SpdySerializedFrame spdy_response_no_error( |
| 1761 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1762 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1763 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1764 | CreateMockRead(spdy_data, 2)}; |
| 1765 | |
| 1766 | // Two error responses. |
| 1767 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1768 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1769 | // Followed by a success response. |
| 1770 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1771 | |
| 1772 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1773 | AddSSLSocketData(); |
| 1774 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1775 | AddSSLSocketData(); |
| 1776 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1777 | AddSSLSocketData(); |
| 1778 | |
| 1779 | TestCompletionCallback callback; |
| 1780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1781 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1782 | |
| 1783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1785 | |
| 1786 | rv = callback.WaitForResult(); |
| 1787 | EXPECT_THAT(rv, IsOk()); |
| 1788 | } |
| 1789 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1790 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1791 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1792 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1793 | } |
| 1794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1795 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1796 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1797 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1798 | } |
| 1799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1800 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1801 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1802 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1803 | } |
| 1804 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1805 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1806 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1807 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1808 | MockRead read_failure(SYNCHRONOUS, |
| 1809 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1810 | "Connection: Keep-Alive\r\n" |
| 1811 | "Content-Length: 6\r\n\r\n" |
| 1812 | "Pickle"); |
| 1813 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1814 | } |
| 1815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1816 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1817 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1818 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1819 | } |
| 1820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1821 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1822 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1823 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | } |
| 1825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1826 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1827 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1828 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1829 | } |
| 1830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1831 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1832 | MockRead read_failure(ASYNC, OK); // EOF |
| 1833 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1834 | } |
| 1835 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1836 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1837 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1838 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1839 | MockRead read_failure(SYNCHRONOUS, |
| 1840 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1841 | "Connection: Keep-Alive\r\n" |
| 1842 | "Content-Length: 6\r\n\r\n" |
| 1843 | "Pickle"); |
| 1844 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1845 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1846 | } |
| 1847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1848 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1849 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1850 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1851 | } |
| 1852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1853 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1854 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1855 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1856 | } |
| 1857 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1858 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1859 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1860 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1861 | } |
| 1862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1863 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1864 | MockRead read_failure(ASYNC, OK); // EOF |
| 1865 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1866 | } |
| 1867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1868 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1869 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1870 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1871 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1875 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1876 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1877 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1878 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1879 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1881 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1882 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1885 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1886 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1887 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1889 | |
| 1890 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1891 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1892 | |
| 1893 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1894 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1895 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1896 | } |
| 1897 | |
| 1898 | // What do various browsers do when the server closes a non-keepalive |
| 1899 | // connection without sending any response header or body? |
| 1900 | // |
| 1901 | // IE7: error page |
| 1902 | // Safari 3.1.2 (Windows): error page |
| 1903 | // Firefox 3.0.1: blank page |
| 1904 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1905 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1906 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1907 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1908 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1909 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1910 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1911 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1912 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1913 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1914 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1915 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1916 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1917 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1918 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1919 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1920 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1921 | // destructor in such situations. |
| 1922 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1923 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1924 | HttpRequestInfo request; |
| 1925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1926 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1927 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1929 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1930 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1931 | |
| 1932 | MockRead data_reads[] = { |
| 1933 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1934 | MockRead("Connection: keep-alive\r\n"), |
| 1935 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1936 | MockRead("hello"), |
| 1937 | MockRead(SYNCHRONOUS, 0), |
| 1938 | }; |
| 1939 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1940 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1941 | |
| 1942 | TestCompletionCallback callback; |
| 1943 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1944 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1946 | |
| 1947 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1948 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1949 | |
| 1950 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1951 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1952 | if (rv == ERR_IO_PENDING) |
| 1953 | rv = callback.WaitForResult(); |
| 1954 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1955 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1956 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1957 | |
| 1958 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1959 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1960 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1961 | } |
| 1962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1963 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1964 | HttpRequestInfo request; |
| 1965 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1966 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1969 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1970 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1971 | |
| 1972 | MockRead data_reads[] = { |
| 1973 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1974 | MockRead("Connection: keep-alive\r\n"), |
| 1975 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1976 | MockRead(SYNCHRONOUS, 0), |
| 1977 | }; |
| 1978 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1980 | |
| 1981 | TestCompletionCallback callback; |
| 1982 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1983 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1985 | |
| 1986 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1987 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1988 | |
| 1989 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1990 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1991 | if (rv == ERR_IO_PENDING) |
| 1992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1993 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1994 | |
| 1995 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1996 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1997 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1998 | } |
| 1999 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2000 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2001 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2002 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2003 | HttpRequestInfo request; |
| 2004 | request.method = "GET"; |
| 2005 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2006 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2007 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2008 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2010 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2011 | const char* request_data = |
| 2012 | "GET / HTTP/1.1\r\n" |
| 2013 | "Host: www.foo.com\r\n" |
| 2014 | "Connection: keep-alive\r\n\r\n"; |
| 2015 | MockWrite data_writes[] = { |
| 2016 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2017 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2018 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2019 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2020 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2021 | }; |
| 2022 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2023 | // Note that because all these reads happen in the same |
| 2024 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2025 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2026 | MockRead data_reads[] = { |
| 2027 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2028 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2029 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2030 | MockRead(ASYNC, 7, |
| 2031 | "HTTP/1.1 302 Found\r\n" |
| 2032 | "Content-Length: 0\r\n\r\n"), |
| 2033 | MockRead(ASYNC, 9, |
| 2034 | "HTTP/1.1 302 Found\r\n" |
| 2035 | "Content-Length: 5\r\n\r\n" |
| 2036 | "hello"), |
| 2037 | MockRead(ASYNC, 11, |
| 2038 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2039 | "Content-Length: 0\r\n\r\n"), |
| 2040 | MockRead(ASYNC, 13, |
| 2041 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2042 | "Content-Length: 5\r\n\r\n" |
| 2043 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2044 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2045 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2046 | // the set_busy_before_sync_reads(true) call, while the |
| 2047 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2048 | // reuseable. See http://crbug.com/544255. |
| 2049 | MockRead(ASYNC, 15, |
| 2050 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2051 | "Content-Length: 5\r\n\r\n"), |
| 2052 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2053 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2054 | MockRead(ASYNC, 18, |
| 2055 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2056 | "Content-Length: 5\r\n\r\n" |
| 2057 | "he"), |
| 2058 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2059 | |
| 2060 | // The body of the final request is actually read. |
| 2061 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2062 | MockRead(ASYNC, 22, "hello"), |
| 2063 | }; |
| 2064 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2065 | arraysize(data_writes)); |
| 2066 | data.set_busy_before_sync_reads(true); |
| 2067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2068 | |
| 2069 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2070 | std::string response_lines[kNumUnreadBodies]; |
| 2071 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2072 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2073 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2074 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2075 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2076 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2077 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2079 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2080 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2081 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2082 | LoadTimingInfo load_timing_info; |
| 2083 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2084 | if (i == 0) { |
| 2085 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2086 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2087 | } else { |
| 2088 | TestLoadTimingReused(load_timing_info); |
| 2089 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2090 | } |
| 2091 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2092 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2093 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2094 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2095 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2096 | response_lines[i] = response->headers->GetStatusLine(); |
| 2097 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2098 | // Delete the transaction without reading the response bodies. Then spin |
| 2099 | // the message loop, so the response bodies are drained. |
| 2100 | trans.reset(); |
| 2101 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2102 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2103 | |
| 2104 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2105 | "HTTP/1.1 204 No Content", |
| 2106 | "HTTP/1.1 205 Reset Content", |
| 2107 | "HTTP/1.1 304 Not Modified", |
| 2108 | "HTTP/1.1 302 Found", |
| 2109 | "HTTP/1.1 302 Found", |
| 2110 | "HTTP/1.1 301 Moved Permanently", |
| 2111 | "HTTP/1.1 301 Moved Permanently", |
| 2112 | "HTTP/1.1 200 Hunky-Dory", |
| 2113 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2114 | }; |
| 2115 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2116 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2117 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2118 | |
| 2119 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2120 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2122 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2124 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2125 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2126 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2127 | ASSERT_TRUE(response); |
| 2128 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2130 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2131 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2133 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2134 | } |
| 2135 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2136 | // Sockets that receive extra data after a response is complete should not be |
| 2137 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2138 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2140 | MockWrite data_writes1[] = { |
| 2141 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2142 | "Host: www.borked.com\r\n" |
| 2143 | "Connection: keep-alive\r\n\r\n"), |
| 2144 | }; |
| 2145 | |
| 2146 | MockRead data_reads1[] = { |
| 2147 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2148 | "Connection: keep-alive\r\n" |
| 2149 | "Content-Length: 22\r\n\r\n" |
| 2150 | "This server is borked."), |
| 2151 | }; |
| 2152 | |
| 2153 | MockWrite data_writes2[] = { |
| 2154 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2155 | "Host: www.borked.com\r\n" |
| 2156 | "Connection: keep-alive\r\n\r\n"), |
| 2157 | }; |
| 2158 | |
| 2159 | MockRead data_reads2[] = { |
| 2160 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2161 | "Content-Length: 3\r\n\r\n" |
| 2162 | "foo"), |
| 2163 | }; |
| 2164 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2165 | data_writes1, arraysize(data_writes1)); |
| 2166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2167 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2168 | data_writes2, arraysize(data_writes2)); |
| 2169 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2170 | |
| 2171 | TestCompletionCallback callback; |
| 2172 | HttpRequestInfo request1; |
| 2173 | request1.method = "HEAD"; |
| 2174 | request1.url = GURL("http://www.borked.com/"); |
| 2175 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2176 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2177 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2178 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2179 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2180 | |
| 2181 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2182 | ASSERT_TRUE(response1); |
| 2183 | ASSERT_TRUE(response1->headers); |
| 2184 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2185 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2186 | |
| 2187 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2188 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2189 | EXPECT_EQ("", response_data1); |
| 2190 | // Deleting the transaction attempts to release the socket back into the |
| 2191 | // socket pool. |
| 2192 | trans1.reset(); |
| 2193 | |
| 2194 | HttpRequestInfo request2; |
| 2195 | request2.method = "GET"; |
| 2196 | request2.url = GURL("http://www.borked.com/foo"); |
| 2197 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2198 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2199 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2200 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2201 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2202 | |
| 2203 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2204 | ASSERT_TRUE(response2); |
| 2205 | ASSERT_TRUE(response2->headers); |
| 2206 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2207 | |
| 2208 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2209 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2210 | EXPECT_EQ("foo", response_data2); |
| 2211 | } |
| 2212 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2213 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2215 | MockWrite data_writes1[] = { |
| 2216 | MockWrite("GET / HTTP/1.1\r\n" |
| 2217 | "Host: www.borked.com\r\n" |
| 2218 | "Connection: keep-alive\r\n\r\n"), |
| 2219 | }; |
| 2220 | |
| 2221 | MockRead data_reads1[] = { |
| 2222 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2223 | "Connection: keep-alive\r\n" |
| 2224 | "Content-Length: 22\r\n\r\n" |
| 2225 | "This server is borked." |
| 2226 | "Bonus data!"), |
| 2227 | }; |
| 2228 | |
| 2229 | MockWrite data_writes2[] = { |
| 2230 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2231 | "Host: www.borked.com\r\n" |
| 2232 | "Connection: keep-alive\r\n\r\n"), |
| 2233 | }; |
| 2234 | |
| 2235 | MockRead data_reads2[] = { |
| 2236 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2237 | "Content-Length: 3\r\n\r\n" |
| 2238 | "foo"), |
| 2239 | }; |
| 2240 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2241 | data_writes1, arraysize(data_writes1)); |
| 2242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2243 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2244 | data_writes2, arraysize(data_writes2)); |
| 2245 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2246 | |
| 2247 | TestCompletionCallback callback; |
| 2248 | HttpRequestInfo request1; |
| 2249 | request1.method = "GET"; |
| 2250 | request1.url = GURL("http://www.borked.com/"); |
| 2251 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2252 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2253 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2254 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2255 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2256 | |
| 2257 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2258 | ASSERT_TRUE(response1); |
| 2259 | ASSERT_TRUE(response1->headers); |
| 2260 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2261 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2262 | |
| 2263 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2264 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2265 | EXPECT_EQ("This server is borked.", response_data1); |
| 2266 | // Deleting the transaction attempts to release the socket back into the |
| 2267 | // socket pool. |
| 2268 | trans1.reset(); |
| 2269 | |
| 2270 | HttpRequestInfo request2; |
| 2271 | request2.method = "GET"; |
| 2272 | request2.url = GURL("http://www.borked.com/foo"); |
| 2273 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2274 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2275 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2276 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2277 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2278 | |
| 2279 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2280 | ASSERT_TRUE(response2); |
| 2281 | ASSERT_TRUE(response2->headers); |
| 2282 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2283 | |
| 2284 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2285 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2286 | EXPECT_EQ("foo", response_data2); |
| 2287 | } |
| 2288 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2289 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2291 | MockWrite data_writes1[] = { |
| 2292 | MockWrite("GET / HTTP/1.1\r\n" |
| 2293 | "Host: www.borked.com\r\n" |
| 2294 | "Connection: keep-alive\r\n\r\n"), |
| 2295 | }; |
| 2296 | |
| 2297 | MockRead data_reads1[] = { |
| 2298 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2299 | "Connection: keep-alive\r\n" |
| 2300 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2301 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2302 | MockRead("0\r\n\r\nBonus data!"), |
| 2303 | }; |
| 2304 | |
| 2305 | MockWrite data_writes2[] = { |
| 2306 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2307 | "Host: www.borked.com\r\n" |
| 2308 | "Connection: keep-alive\r\n\r\n"), |
| 2309 | }; |
| 2310 | |
| 2311 | MockRead data_reads2[] = { |
| 2312 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2313 | "Content-Length: 3\r\n\r\n" |
| 2314 | "foo"), |
| 2315 | }; |
| 2316 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2317 | data_writes1, arraysize(data_writes1)); |
| 2318 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2319 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2320 | data_writes2, arraysize(data_writes2)); |
| 2321 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2322 | |
| 2323 | TestCompletionCallback callback; |
| 2324 | HttpRequestInfo request1; |
| 2325 | request1.method = "GET"; |
| 2326 | request1.url = GURL("http://www.borked.com/"); |
| 2327 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2328 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2330 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2331 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2332 | |
| 2333 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2334 | ASSERT_TRUE(response1); |
| 2335 | ASSERT_TRUE(response1->headers); |
| 2336 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2337 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2338 | |
| 2339 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2340 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2341 | EXPECT_EQ("This server is borked.", response_data1); |
| 2342 | // Deleting the transaction attempts to release the socket back into the |
| 2343 | // socket pool. |
| 2344 | trans1.reset(); |
| 2345 | |
| 2346 | HttpRequestInfo request2; |
| 2347 | request2.method = "GET"; |
| 2348 | request2.url = GURL("http://www.borked.com/foo"); |
| 2349 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2350 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2351 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2352 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2353 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2354 | |
| 2355 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2356 | ASSERT_TRUE(response2); |
| 2357 | ASSERT_TRUE(response2->headers); |
| 2358 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2359 | |
| 2360 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2361 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2362 | EXPECT_EQ("foo", response_data2); |
| 2363 | } |
| 2364 | |
| 2365 | // This is a little different from the others - it tests the case that the |
| 2366 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2367 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2368 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2369 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2371 | MockWrite data_writes1[] = { |
| 2372 | MockWrite("GET / HTTP/1.1\r\n" |
| 2373 | "Host: www.borked.com\r\n" |
| 2374 | "Connection: keep-alive\r\n\r\n"), |
| 2375 | }; |
| 2376 | |
| 2377 | MockRead data_reads1[] = { |
| 2378 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2379 | "Connection: keep-alive\r\n" |
| 2380 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2381 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2382 | MockRead("0\r\n\r\nBonus data!"), |
| 2383 | }; |
| 2384 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2385 | data_writes1, arraysize(data_writes1)); |
| 2386 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2387 | |
| 2388 | TestCompletionCallback callback; |
| 2389 | HttpRequestInfo request1; |
| 2390 | request1.method = "GET"; |
| 2391 | request1.url = GURL("http://www.borked.com/"); |
| 2392 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2393 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2394 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2395 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2396 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2397 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2398 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2399 | ASSERT_TRUE(response1); |
| 2400 | ASSERT_TRUE(response1->headers); |
| 2401 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2402 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2403 | |
| 2404 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2405 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2406 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2407 | |
| 2408 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2409 | // socket can't be reused, rather than returning it to the socket pool. |
| 2410 | base::RunLoop().RunUntilIdle(); |
| 2411 | |
| 2412 | // There should be no idle sockets in the pool. |
| 2413 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2414 | } |
| 2415 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2416 | // Test the request-challenge-retry sequence for basic auth. |
| 2417 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2418 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2419 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2420 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2421 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2422 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2423 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2424 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2427 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2428 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2429 | MockWrite( |
| 2430 | "GET / HTTP/1.1\r\n" |
| 2431 | "Host: www.example.org\r\n" |
| 2432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2433 | }; |
| 2434 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2435 | MockRead data_reads1[] = { |
| 2436 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2437 | // Give a couple authenticate options (only the middle one is actually |
| 2438 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2439 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2440 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2441 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2442 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2443 | // Large content-length -- won't matter, as connection will be reset. |
| 2444 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2445 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2446 | }; |
| 2447 | |
| 2448 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2449 | // be issuing -- the final header line contains the credentials. |
| 2450 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2451 | MockWrite( |
| 2452 | "GET / HTTP/1.1\r\n" |
| 2453 | "Host: www.example.org\r\n" |
| 2454 | "Connection: keep-alive\r\n" |
| 2455 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2456 | }; |
| 2457 | |
| 2458 | // Lastly, the server responds with the actual content. |
| 2459 | MockRead data_reads2[] = { |
| 2460 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2461 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2462 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2463 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2464 | }; |
| 2465 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2467 | data_writes1, arraysize(data_writes1)); |
| 2468 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2469 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2473 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2474 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2475 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2477 | |
| 2478 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2479 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2480 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2481 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2482 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2483 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2484 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2485 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2486 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2487 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2488 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2489 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2490 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2491 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2492 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2494 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2496 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2498 | |
| 2499 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2501 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2502 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2503 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2504 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2505 | // The load timing after restart should have a new socket ID, and times after |
| 2506 | // those of the first load timing. |
| 2507 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2508 | load_timing_info2.connect_timing.connect_start); |
| 2509 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2510 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2511 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2512 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2513 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2514 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2516 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2517 | ASSERT_TRUE(response); |
| 2518 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2519 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2520 | } |
| 2521 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2522 | // Test the request-challenge-retry sequence for basic auth. |
| 2523 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2524 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2525 | HttpRequestInfo request; |
| 2526 | request.method = "GET"; |
| 2527 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2528 | |
| 2529 | TestNetLog log; |
| 2530 | MockHostResolver* resolver = new MockHostResolver(); |
| 2531 | session_deps_.net_log = &log; |
| 2532 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2533 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2535 | |
| 2536 | resolver->rules()->ClearRules(); |
| 2537 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2538 | |
| 2539 | MockWrite data_writes1[] = { |
| 2540 | MockWrite("GET / HTTP/1.1\r\n" |
| 2541 | "Host: www.example.org\r\n" |
| 2542 | "Connection: keep-alive\r\n\r\n"), |
| 2543 | }; |
| 2544 | |
| 2545 | MockRead data_reads1[] = { |
| 2546 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2547 | // Give a couple authenticate options (only the middle one is actually |
| 2548 | // supported). |
| 2549 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2550 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2551 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2552 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2553 | // Large content-length -- won't matter, as connection will be reset. |
| 2554 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2555 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2556 | }; |
| 2557 | |
| 2558 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2559 | // be issuing -- the final header line contains the credentials. |
| 2560 | MockWrite data_writes2[] = { |
| 2561 | MockWrite("GET / HTTP/1.1\r\n" |
| 2562 | "Host: www.example.org\r\n" |
| 2563 | "Connection: keep-alive\r\n" |
| 2564 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2565 | }; |
| 2566 | |
| 2567 | // Lastly, the server responds with the actual content. |
| 2568 | MockRead data_reads2[] = { |
| 2569 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2570 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2571 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2572 | }; |
| 2573 | |
| 2574 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2575 | data_writes1, arraysize(data_writes1)); |
| 2576 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2577 | data_writes2, arraysize(data_writes2)); |
| 2578 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2579 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2580 | |
| 2581 | TestCompletionCallback callback1; |
| 2582 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2583 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2584 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2585 | |
| 2586 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2587 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2588 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2589 | |
| 2590 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2591 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2592 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2593 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2596 | ASSERT_TRUE(response); |
| 2597 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2598 | |
| 2599 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2600 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2601 | ASSERT_FALSE(endpoint.address().empty()); |
| 2602 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2603 | |
| 2604 | resolver->rules()->ClearRules(); |
| 2605 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2606 | |
| 2607 | TestCompletionCallback callback2; |
| 2608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2609 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2610 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2611 | |
| 2612 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2613 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2614 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2615 | // The load timing after restart should have a new socket ID, and times after |
| 2616 | // those of the first load timing. |
| 2617 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2618 | load_timing_info2.connect_timing.connect_start); |
| 2619 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2620 | |
| 2621 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2622 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2623 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2624 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2626 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2627 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2628 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2629 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2631 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2632 | ASSERT_FALSE(endpoint.address().empty()); |
| 2633 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2634 | } |
| 2635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2636 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2637 | HttpRequestInfo request; |
| 2638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2639 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2640 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2644 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2645 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2646 | MockWrite( |
| 2647 | "GET / HTTP/1.1\r\n" |
| 2648 | "Host: www.example.org\r\n" |
| 2649 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2650 | }; |
| 2651 | |
| 2652 | MockRead data_reads[] = { |
| 2653 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2654 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2655 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2656 | // Large content-length -- won't matter, as connection will be reset. |
| 2657 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2658 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2659 | }; |
| 2660 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2661 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2662 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2663 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2664 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2665 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2666 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2668 | |
| 2669 | rv = callback.WaitForResult(); |
| 2670 | EXPECT_EQ(0, rv); |
| 2671 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2672 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2673 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2674 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2675 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2678 | ASSERT_TRUE(response); |
| 2679 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2680 | } |
| 2681 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2682 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2683 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2684 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2685 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2686 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2687 | // reused. See http://crbug.com/544255. |
| 2688 | for (int i = 0; i < 2; ++i) { |
| 2689 | HttpRequestInfo request; |
| 2690 | request.method = "GET"; |
| 2691 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2692 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2693 | TestNetLog log; |
| 2694 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2696 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2697 | MockWrite data_writes[] = { |
| 2698 | MockWrite(ASYNC, 0, |
| 2699 | "GET / HTTP/1.1\r\n" |
| 2700 | "Host: www.example.org\r\n" |
| 2701 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2704 | // be issuing -- the final header line contains the credentials. |
| 2705 | MockWrite(ASYNC, 6, |
| 2706 | "GET / HTTP/1.1\r\n" |
| 2707 | "Host: www.example.org\r\n" |
| 2708 | "Connection: keep-alive\r\n" |
| 2709 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2710 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2711 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2712 | MockRead data_reads[] = { |
| 2713 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2714 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2715 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2716 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2717 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2719 | // Lastly, the server responds with the actual content. |
| 2720 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2721 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2722 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2723 | MockRead(ASYNC, 10, "Hello"), |
| 2724 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2726 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2727 | arraysize(data_writes)); |
| 2728 | data.set_busy_before_sync_reads(true); |
| 2729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2730 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2731 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2734 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2735 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2736 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2737 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2738 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2739 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2742 | ASSERT_TRUE(response); |
| 2743 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2744 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2745 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2747 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2748 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2749 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2750 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2751 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2752 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2753 | TestLoadTimingReused(load_timing_info2); |
| 2754 | // The load timing after restart should have the same socket ID, and times |
| 2755 | // those of the first load timing. |
| 2756 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2757 | load_timing_info2.send_start); |
| 2758 | 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] | 2759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2760 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2761 | ASSERT_TRUE(response); |
| 2762 | EXPECT_FALSE(response->auth_challenge); |
| 2763 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2764 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2765 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2767 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2768 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2770 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2771 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2772 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2776 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2777 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2778 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2780 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2783 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2785 | MockWrite("GET / HTTP/1.1\r\n" |
| 2786 | "Host: www.example.org\r\n" |
| 2787 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2790 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2791 | MockWrite("GET / HTTP/1.1\r\n" |
| 2792 | "Host: www.example.org\r\n" |
| 2793 | "Connection: keep-alive\r\n" |
| 2794 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | }; |
| 2796 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | MockRead data_reads1[] = { |
| 2798 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2799 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2800 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
| 2802 | // Lastly, the server responds with the actual content. |
| 2803 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2804 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2805 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2806 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | }; |
| 2808 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2809 | // An incorrect reconnect would cause this to be read. |
| 2810 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2811 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2812 | }; |
| 2813 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2814 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2815 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2816 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2817 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2818 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2819 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2821 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2824 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2826 | |
| 2827 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2830 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2831 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2832 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2834 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2836 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
| 2839 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2841 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2842 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2843 | ASSERT_TRUE(response); |
| 2844 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2845 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2849 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2850 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2851 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2853 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2854 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2856 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2857 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2858 | MockWrite("GET / HTTP/1.1\r\n" |
| 2859 | "Host: www.example.org\r\n" |
| 2860 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2862 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2863 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2864 | MockWrite("GET / HTTP/1.1\r\n" |
| 2865 | "Host: www.example.org\r\n" |
| 2866 | "Connection: keep-alive\r\n" |
| 2867 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2868 | }; |
| 2869 | |
| 2870 | // Respond with 5 kb of response body. |
| 2871 | std::string large_body_string("Unauthorized"); |
| 2872 | large_body_string.append(5 * 1024, ' '); |
| 2873 | large_body_string.append("\r\n"); |
| 2874 | |
| 2875 | MockRead data_reads1[] = { |
| 2876 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2877 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2879 | // 5134 = 12 + 5 * 1024 + 2 |
| 2880 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2881 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2882 | |
| 2883 | // Lastly, the server responds with the actual content. |
| 2884 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2885 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2886 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2887 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2888 | }; |
| 2889 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2890 | // An incorrect reconnect would cause this to be read. |
| 2891 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2892 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2893 | }; |
| 2894 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2895 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2896 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2897 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2898 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2902 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2905 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2907 | |
| 2908 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2912 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2913 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2915 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2917 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | |
| 2920 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2921 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2923 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2924 | ASSERT_TRUE(response); |
| 2925 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2926 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2927 | } |
| 2928 | |
| 2929 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2930 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2931 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2932 | HttpRequestInfo request; |
| 2933 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2934 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2936 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2937 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2938 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2939 | MockWrite( |
| 2940 | "GET / HTTP/1.1\r\n" |
| 2941 | "Host: www.example.org\r\n" |
| 2942 | "Connection: keep-alive\r\n\r\n"), |
| 2943 | // This simulates the seemingly successful write to a closed connection |
| 2944 | // if the bug is not fixed. |
| 2945 | MockWrite( |
| 2946 | "GET / HTTP/1.1\r\n" |
| 2947 | "Host: www.example.org\r\n" |
| 2948 | "Connection: keep-alive\r\n" |
| 2949 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2950 | }; |
| 2951 | |
| 2952 | MockRead data_reads1[] = { |
| 2953 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2954 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2956 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2957 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2958 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2959 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2960 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2961 | }; |
| 2962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2963 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2964 | // be issuing -- the final header line contains the credentials. |
| 2965 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2966 | MockWrite( |
| 2967 | "GET / HTTP/1.1\r\n" |
| 2968 | "Host: www.example.org\r\n" |
| 2969 | "Connection: keep-alive\r\n" |
| 2970 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2971 | }; |
| 2972 | |
| 2973 | // Lastly, the server responds with the actual content. |
| 2974 | MockRead data_reads2[] = { |
| 2975 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2976 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2977 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2978 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2979 | }; |
| 2980 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2981 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2982 | data_writes1, arraysize(data_writes1)); |
| 2983 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2984 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2985 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2986 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2988 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2990 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2991 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2993 | |
| 2994 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2997 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2998 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2999 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3000 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3001 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3003 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3005 | |
| 3006 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3007 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3009 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3010 | ASSERT_TRUE(response); |
| 3011 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3012 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3013 | } |
| 3014 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3015 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3016 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3017 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3018 | HttpRequestInfo request; |
| 3019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3020 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3021 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3022 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3023 | |
| 3024 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3025 | session_deps_.proxy_resolution_service = |
| 3026 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3027 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3028 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3029 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3030 | |
| 3031 | // Since we have proxy, should try to establish tunnel. |
| 3032 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3033 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3034 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3035 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3036 | }; |
| 3037 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3038 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3039 | // connection. |
| 3040 | MockRead data_reads1[] = { |
| 3041 | // No credentials. |
| 3042 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3043 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3044 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3045 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3046 | // Since the first connection couldn't be reused, need to establish another |
| 3047 | // once given credentials. |
| 3048 | MockWrite data_writes2[] = { |
| 3049 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3050 | // be issuing -- the final header line contains the credentials. |
| 3051 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3052 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3053 | "Proxy-Connection: keep-alive\r\n" |
| 3054 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3055 | |
| 3056 | MockWrite("GET / HTTP/1.1\r\n" |
| 3057 | "Host: www.example.org\r\n" |
| 3058 | "Connection: keep-alive\r\n\r\n"), |
| 3059 | }; |
| 3060 | |
| 3061 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3062 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3063 | |
| 3064 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3065 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3066 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3067 | MockRead(SYNCHRONOUS, "hello"), |
| 3068 | }; |
| 3069 | |
| 3070 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3071 | data_writes1, arraysize(data_writes1)); |
| 3072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3073 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3074 | data_writes2, arraysize(data_writes2)); |
| 3075 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3076 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3078 | |
| 3079 | TestCompletionCallback callback1; |
| 3080 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3081 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3082 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3083 | |
| 3084 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3086 | |
| 3087 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3088 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3089 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3090 | log.GetEntries(&entries); |
| 3091 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3092 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3093 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3094 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3095 | entries, pos, |
| 3096 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3097 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | |
| 3099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3100 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3101 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3102 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3103 | EXPECT_EQ(407, response->headers->response_code()); |
| 3104 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3105 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3106 | |
| 3107 | LoadTimingInfo load_timing_info; |
| 3108 | // CONNECT requests and responses are handled at the connect job level, so |
| 3109 | // the transaction does not yet have a connection. |
| 3110 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3111 | |
| 3112 | TestCompletionCallback callback2; |
| 3113 | |
| 3114 | rv = |
| 3115 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3117 | |
| 3118 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3119 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3120 | |
| 3121 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3122 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3123 | |
| 3124 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3125 | EXPECT_EQ(200, response->headers->response_code()); |
| 3126 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3127 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3128 | |
| 3129 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3130 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3131 | |
| 3132 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3133 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3134 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3135 | |
| 3136 | trans.reset(); |
| 3137 | session->CloseAllConnections(); |
| 3138 | } |
| 3139 | |
| 3140 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3141 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3142 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3143 | HttpRequestInfo request; |
| 3144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3145 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3146 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3147 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3148 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3149 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3150 | session_deps_.proxy_resolution_service = |
| 3151 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3152 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3153 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3155 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3156 | // Since we have proxy, should try to establish tunnel. |
| 3157 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3158 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3159 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3160 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3161 | }; |
| 3162 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3163 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3164 | // connection. |
| 3165 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3166 | // No credentials. |
| 3167 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3168 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3169 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3170 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3171 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3172 | MockWrite data_writes2[] = { |
| 3173 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3174 | // be issuing -- the final header line contains the credentials. |
| 3175 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3176 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3177 | "Proxy-Connection: keep-alive\r\n" |
| 3178 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3179 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3180 | MockWrite("GET / HTTP/1.1\r\n" |
| 3181 | "Host: www.example.org\r\n" |
| 3182 | "Connection: keep-alive\r\n\r\n"), |
| 3183 | }; |
| 3184 | |
| 3185 | MockRead data_reads2[] = { |
| 3186 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3187 | |
| 3188 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3189 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3190 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3191 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3192 | }; |
| 3193 | |
| 3194 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3195 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3196 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3197 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3198 | data_writes2, arraysize(data_writes2)); |
| 3199 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3200 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3201 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3202 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3203 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3204 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3205 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3206 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3208 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3210 | |
| 3211 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3212 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3213 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3214 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3215 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3216 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3217 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3218 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3219 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3220 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3221 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3222 | |
| 3223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3224 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3225 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3226 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3227 | EXPECT_EQ(407, response->headers->response_code()); |
| 3228 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3229 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3230 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3231 | LoadTimingInfo load_timing_info; |
| 3232 | // CONNECT requests and responses are handled at the connect job level, so |
| 3233 | // the transaction does not yet have a connection. |
| 3234 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3236 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3238 | rv = trans->RestartWithAuth( |
| 3239 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3241 | |
| 3242 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3243 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3244 | |
| 3245 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3246 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3247 | |
| 3248 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3249 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3250 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3251 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3252 | |
| 3253 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3254 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3255 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3256 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3257 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3258 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3259 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3260 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3261 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3262 | } |
| 3263 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3264 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3265 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3266 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3267 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3268 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3269 | // reused. See http://crbug.com/544255. |
| 3270 | for (int i = 0; i < 2; ++i) { |
| 3271 | HttpRequestInfo request; |
| 3272 | request.method = "GET"; |
| 3273 | request.url = GURL("https://www.example.org/"); |
| 3274 | // Ensure that proxy authentication is attempted even |
| 3275 | // when the no authentication data flag is set. |
| 3276 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3278 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3279 | session_deps_.proxy_resolution_service = |
| 3280 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3281 | BoundTestNetLog log; |
| 3282 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3285 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3287 | // Since we have proxy, should try to establish tunnel. |
| 3288 | MockWrite data_writes1[] = { |
| 3289 | MockWrite(ASYNC, 0, |
| 3290 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3291 | "Host: www.example.org:443\r\n" |
| 3292 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3294 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3295 | // be issuing -- the final header line contains the credentials. |
| 3296 | MockWrite(ASYNC, 3, |
| 3297 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3298 | "Host: www.example.org:443\r\n" |
| 3299 | "Proxy-Connection: keep-alive\r\n" |
| 3300 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3301 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3302 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3303 | // The proxy responds to the connect with a 407, using a persistent |
| 3304 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3305 | MockRead data_reads1[] = { |
| 3306 | // No credentials. |
| 3307 | MockRead(ASYNC, 1, |
| 3308 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3309 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3310 | "Proxy-Connection: keep-alive\r\n" |
| 3311 | "Content-Length: 10\r\n\r\n"), |
| 3312 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3313 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3314 | // Wrong credentials (wrong password). |
| 3315 | MockRead(ASYNC, 4, |
| 3316 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3317 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3318 | "Proxy-Connection: keep-alive\r\n" |
| 3319 | "Content-Length: 10\r\n\r\n"), |
| 3320 | // No response body because the test stops reading here. |
| 3321 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3322 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3323 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3324 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3325 | arraysize(data_writes1)); |
| 3326 | data1.set_busy_before_sync_reads(true); |
| 3327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3328 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3331 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3332 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3334 | TestNetLogEntry::List entries; |
| 3335 | log.GetEntries(&entries); |
| 3336 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3337 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3338 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3339 | ExpectLogContainsSomewhere( |
| 3340 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3341 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3342 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | ASSERT_TRUE(response); |
| 3346 | ASSERT_TRUE(response->headers); |
| 3347 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3348 | EXPECT_EQ(407, response->headers->response_code()); |
| 3349 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3350 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3351 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3352 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3353 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3355 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3356 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3357 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3360 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3361 | ASSERT_TRUE(response); |
| 3362 | ASSERT_TRUE(response->headers); |
| 3363 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3364 | EXPECT_EQ(407, response->headers->response_code()); |
| 3365 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3366 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3367 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3368 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3369 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3370 | // out of scope. |
| 3371 | session->CloseAllConnections(); |
| 3372 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3376 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3377 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3378 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3379 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3380 | // reused. See http://crbug.com/544255. |
| 3381 | for (int i = 0; i < 2; ++i) { |
| 3382 | HttpRequestInfo request; |
| 3383 | request.method = "GET"; |
| 3384 | request.url = GURL("https://www.example.org/"); |
| 3385 | // Ensure that proxy authentication is attempted even |
| 3386 | // when the no authentication data flag is set. |
| 3387 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3388 | |
| 3389 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3390 | session_deps_.proxy_resolution_service = |
| 3391 | ProxyResolutionService::CreateFixed("myproxy:70"); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3392 | BoundTestNetLog log; |
| 3393 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3396 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3397 | |
| 3398 | // Since we have proxy, should try to establish tunnel. |
| 3399 | MockWrite data_writes1[] = { |
| 3400 | MockWrite(ASYNC, 0, |
| 3401 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3402 | "Host: www.example.org:443\r\n" |
| 3403 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3405 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3406 | // be issuing -- the final header line contains the credentials. |
| 3407 | MockWrite(ASYNC, 3, |
| 3408 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3409 | "Host: www.example.org:443\r\n" |
| 3410 | "Proxy-Connection: keep-alive\r\n" |
| 3411 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3412 | }; |
| 3413 | |
| 3414 | // The proxy responds to the connect with a 407, using a persistent |
| 3415 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3416 | MockRead data_reads1[] = { |
| 3417 | // No credentials. |
| 3418 | MockRead(ASYNC, 1, |
| 3419 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3420 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3421 | "Content-Length: 10\r\n\r\n"), |
| 3422 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3423 | |
| 3424 | // Wrong credentials (wrong password). |
| 3425 | MockRead(ASYNC, 4, |
| 3426 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3427 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3428 | "Content-Length: 10\r\n\r\n"), |
| 3429 | // No response body because the test stops reading here. |
| 3430 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3431 | }; |
| 3432 | |
| 3433 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3434 | arraysize(data_writes1)); |
| 3435 | data1.set_busy_before_sync_reads(true); |
| 3436 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3437 | |
| 3438 | TestCompletionCallback callback1; |
| 3439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3440 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3441 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3442 | |
| 3443 | TestNetLogEntry::List entries; |
| 3444 | log.GetEntries(&entries); |
| 3445 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3446 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3447 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3448 | ExpectLogContainsSomewhere( |
| 3449 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3450 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3451 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | ASSERT_TRUE(response); |
| 3455 | ASSERT_TRUE(response->headers); |
| 3456 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3457 | EXPECT_EQ(407, response->headers->response_code()); |
| 3458 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3459 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3460 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3461 | |
| 3462 | TestCompletionCallback callback2; |
| 3463 | |
| 3464 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3465 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3466 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3467 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3469 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3470 | ASSERT_TRUE(response); |
| 3471 | ASSERT_TRUE(response->headers); |
| 3472 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3473 | EXPECT_EQ(407, response->headers->response_code()); |
| 3474 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3475 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3476 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3477 | |
| 3478 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3479 | // out of scope. |
| 3480 | session->CloseAllConnections(); |
| 3481 | } |
| 3482 | } |
| 3483 | |
| 3484 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3485 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3486 | // the case the server sends extra data on the original socket, so it can't be |
| 3487 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3488 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3489 | HttpRequestInfo request; |
| 3490 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3491 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3492 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3493 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3494 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3495 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3496 | session_deps_.proxy_resolution_service = |
| 3497 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3498 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3499 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3501 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3502 | // Since we have proxy, should try to establish tunnel. |
| 3503 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3504 | MockWrite(ASYNC, 0, |
| 3505 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3506 | "Host: www.example.org:443\r\n" |
| 3507 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3508 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3509 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3510 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3511 | // extra data, so the socket cannot be reused. |
| 3512 | MockRead data_reads1[] = { |
| 3513 | // No credentials. |
| 3514 | MockRead(ASYNC, 1, |
| 3515 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3516 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3517 | "Content-Length: 10\r\n\r\n"), |
| 3518 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3519 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3520 | }; |
| 3521 | |
| 3522 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3523 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3524 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3525 | MockWrite(ASYNC, 0, |
| 3526 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3527 | "Host: www.example.org:443\r\n" |
| 3528 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3529 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3530 | |
| 3531 | MockWrite(ASYNC, 2, |
| 3532 | "GET / HTTP/1.1\r\n" |
| 3533 | "Host: www.example.org\r\n" |
| 3534 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3535 | }; |
| 3536 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | MockRead data_reads2[] = { |
| 3538 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3539 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3540 | MockRead(ASYNC, 3, |
| 3541 | "HTTP/1.1 200 OK\r\n" |
| 3542 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3543 | "Content-Length: 5\r\n\r\n"), |
| 3544 | // No response body because the test stops reading here. |
| 3545 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3546 | }; |
| 3547 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3548 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3549 | arraysize(data_writes1)); |
| 3550 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3551 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3552 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3553 | arraysize(data_writes2)); |
| 3554 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3555 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3558 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3559 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3560 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3561 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3562 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3563 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3564 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3565 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3566 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3567 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3568 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3569 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3570 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3571 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3572 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3573 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3574 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3575 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3576 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3577 | ASSERT_TRUE(response); |
| 3578 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3579 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3580 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3581 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3582 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3583 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3584 | LoadTimingInfo load_timing_info; |
| 3585 | // CONNECT requests and responses are handled at the connect job level, so |
| 3586 | // the transaction does not yet have a connection. |
| 3587 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3589 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3590 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3591 | rv = |
| 3592 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3593 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3594 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3595 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3596 | EXPECT_EQ(200, response->headers->response_code()); |
| 3597 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3598 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3599 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3600 | // The password prompt info should not be set. |
| 3601 | EXPECT_FALSE(response->auth_challenge); |
| 3602 | |
| 3603 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3604 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3605 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3606 | |
| 3607 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3608 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3609 | } |
| 3610 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3611 | // Test the case a proxy closes a socket while the challenge body is being |
| 3612 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3613 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3614 | HttpRequestInfo request; |
| 3615 | request.method = "GET"; |
| 3616 | request.url = GURL("https://www.example.org/"); |
| 3617 | // Ensure that proxy authentication is attempted even |
| 3618 | // when the no authentication data flag is set. |
| 3619 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3620 | |
| 3621 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3622 | session_deps_.proxy_resolution_service = |
| 3623 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3624 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3627 | |
| 3628 | // Since we have proxy, should try to establish tunnel. |
| 3629 | MockWrite data_writes1[] = { |
| 3630 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3631 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3632 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3633 | }; |
| 3634 | |
| 3635 | // The proxy responds to the connect with a 407, using a persistent |
| 3636 | // connection. |
| 3637 | MockRead data_reads1[] = { |
| 3638 | // No credentials. |
| 3639 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3640 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3641 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3642 | // Server hands up in the middle of the body. |
| 3643 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3644 | }; |
| 3645 | |
| 3646 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3647 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3648 | // be issuing -- the final header line contains the credentials. |
| 3649 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3650 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3651 | "Proxy-Connection: keep-alive\r\n" |
| 3652 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3653 | |
| 3654 | MockWrite("GET / HTTP/1.1\r\n" |
| 3655 | "Host: www.example.org\r\n" |
| 3656 | "Connection: keep-alive\r\n\r\n"), |
| 3657 | }; |
| 3658 | |
| 3659 | MockRead data_reads2[] = { |
| 3660 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3661 | |
| 3662 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3663 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3664 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3665 | MockRead(SYNCHRONOUS, "hello"), |
| 3666 | }; |
| 3667 | |
| 3668 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3669 | data_writes1, arraysize(data_writes1)); |
| 3670 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3671 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3672 | data_writes2, arraysize(data_writes2)); |
| 3673 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3674 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3676 | |
| 3677 | TestCompletionCallback callback; |
| 3678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3679 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3680 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3681 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3682 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3683 | ASSERT_TRUE(response); |
| 3684 | ASSERT_TRUE(response->headers); |
| 3685 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3686 | EXPECT_EQ(407, response->headers->response_code()); |
| 3687 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3689 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3690 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3692 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3693 | ASSERT_TRUE(response); |
| 3694 | ASSERT_TRUE(response->headers); |
| 3695 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3696 | EXPECT_EQ(200, response->headers->response_code()); |
| 3697 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3698 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3699 | EXPECT_EQ("hello", body); |
| 3700 | } |
| 3701 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3702 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3703 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3704 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3705 | HttpRequestInfo request; |
| 3706 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3707 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3708 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3709 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3710 | session_deps_.proxy_resolution_service = |
| 3711 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3712 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3716 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3717 | // Since we have proxy, should try to establish tunnel. |
| 3718 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3719 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3720 | "Host: www.example.org:443\r\n" |
| 3721 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3722 | }; |
| 3723 | |
| 3724 | // The proxy responds to the connect with a 407. |
| 3725 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3726 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3727 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3728 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3730 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3731 | }; |
| 3732 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3733 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3734 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3735 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3737 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3739 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3741 | |
| 3742 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3745 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3746 | ASSERT_TRUE(response); |
| 3747 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3748 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3749 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3750 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3751 | |
| 3752 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3753 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3754 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3755 | |
| 3756 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3757 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3758 | } |
| 3759 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3760 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3761 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3762 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3763 | HttpRequestInfo request; |
| 3764 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3765 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3766 | |
| 3767 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3768 | session_deps_.proxy_resolution_service = |
| 3769 | ProxyResolutionService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3770 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3774 | |
| 3775 | // Since we have proxy, should try to establish tunnel. |
| 3776 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3777 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3778 | "Host: www.example.org:443\r\n" |
| 3779 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3780 | }; |
| 3781 | |
| 3782 | // The proxy responds to the connect with a 407. |
| 3783 | MockRead data_reads[] = { |
| 3784 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3785 | MockRead("X-Foo: bar\r\n"), |
| 3786 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3787 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3788 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3789 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3790 | }; |
| 3791 | |
| 3792 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3793 | arraysize(data_writes)); |
| 3794 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3795 | |
| 3796 | TestCompletionCallback callback; |
| 3797 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3798 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3800 | |
| 3801 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3802 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3804 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3805 | ASSERT_TRUE(response); |
| 3806 | ASSERT_TRUE(response->headers); |
| 3807 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3808 | EXPECT_EQ(407, response->headers->response_code()); |
| 3809 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3810 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3811 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3812 | |
| 3813 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3814 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3815 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3816 | |
| 3817 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3818 | session->CloseAllConnections(); |
| 3819 | } |
| 3820 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3821 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3822 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3823 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3824 | HttpRequestInfo request; |
| 3825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3826 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3827 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3828 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3831 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3832 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3833 | MockWrite( |
| 3834 | "GET / HTTP/1.1\r\n" |
| 3835 | "Host: www.example.org\r\n" |
| 3836 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3837 | }; |
| 3838 | |
| 3839 | MockRead data_reads1[] = { |
| 3840 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3841 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3842 | // Large content-length -- won't matter, as connection will be reset. |
| 3843 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3844 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3845 | }; |
| 3846 | |
| 3847 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3848 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3849 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3851 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3852 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3853 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3855 | |
| 3856 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3857 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3858 | } |
| 3859 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3860 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3861 | // through a non-authenticating proxy. The request should fail with |
| 3862 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3863 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3864 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3865 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3866 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3867 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3868 | HttpRequestInfo request; |
| 3869 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3870 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3871 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3872 | session_deps_.proxy_resolution_service = |
| 3873 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3874 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3875 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3877 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3878 | // Since we have proxy, should try to establish tunnel. |
| 3879 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3880 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3881 | "Host: www.example.org:443\r\n" |
| 3882 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3883 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3884 | MockWrite("GET / HTTP/1.1\r\n" |
| 3885 | "Host: www.example.org\r\n" |
| 3886 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3887 | }; |
| 3888 | |
| 3889 | MockRead data_reads1[] = { |
| 3890 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3891 | |
| 3892 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3893 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3894 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3895 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3896 | }; |
| 3897 | |
| 3898 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3899 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3900 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3901 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3904 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3906 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3908 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3910 | |
| 3911 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3912 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3913 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3914 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3915 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3916 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3917 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3918 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3919 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3920 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3921 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3922 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3923 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3924 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3925 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3926 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3927 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3928 | HttpRequestInfo request; |
| 3929 | request.method = "GET"; |
| 3930 | request.url = GURL("https://www.example.org/"); |
| 3931 | |
| 3932 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3933 | session_deps_.proxy_resolution_service = |
| 3934 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3935 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3936 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3937 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3938 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3939 | mock_handler->set_allows_default_credentials(true); |
| 3940 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3941 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3942 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3943 | |
| 3944 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3945 | NetLog net_log; |
| 3946 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3947 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3948 | |
| 3949 | // Since we have proxy, should try to establish tunnel. |
| 3950 | MockWrite data_writes1[] = { |
| 3951 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3952 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3953 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3954 | }; |
| 3955 | |
| 3956 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3957 | // connection. |
| 3958 | MockRead data_reads1[] = { |
| 3959 | // No credentials. |
| 3960 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3961 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3962 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3963 | }; |
| 3964 | |
| 3965 | // Since the first connection couldn't be reused, need to establish another |
| 3966 | // once given credentials. |
| 3967 | MockWrite data_writes2[] = { |
| 3968 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3969 | // be issuing -- the final header line contains the credentials. |
| 3970 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3971 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3972 | "Proxy-Connection: keep-alive\r\n" |
| 3973 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3974 | |
| 3975 | MockWrite("GET / HTTP/1.1\r\n" |
| 3976 | "Host: www.example.org\r\n" |
| 3977 | "Connection: keep-alive\r\n\r\n"), |
| 3978 | }; |
| 3979 | |
| 3980 | MockRead data_reads2[] = { |
| 3981 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3982 | |
| 3983 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3984 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3985 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3986 | MockRead(SYNCHRONOUS, "hello"), |
| 3987 | }; |
| 3988 | |
| 3989 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3990 | data_writes1, arraysize(data_writes1)); |
| 3991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3992 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3993 | data_writes2, arraysize(data_writes2)); |
| 3994 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3995 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3997 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3998 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3999 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4000 | |
| 4001 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4002 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4003 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4004 | |
| 4005 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4006 | ASSERT_TRUE(response); |
| 4007 | ASSERT_TRUE(response->headers); |
| 4008 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4009 | EXPECT_EQ(407, response->headers->response_code()); |
| 4010 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4011 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4012 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4013 | |
| 4014 | LoadTimingInfo load_timing_info; |
| 4015 | // CONNECT requests and responses are handled at the connect job level, so |
| 4016 | // the transaction does not yet have a connection. |
| 4017 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4018 | |
| 4019 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4020 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4021 | response = trans->GetResponseInfo(); |
| 4022 | ASSERT_TRUE(response); |
| 4023 | ASSERT_TRUE(response->headers); |
| 4024 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4025 | EXPECT_EQ(200, response->headers->response_code()); |
| 4026 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4027 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4028 | |
| 4029 | // The password prompt info should not be set. |
| 4030 | EXPECT_FALSE(response->auth_challenge); |
| 4031 | |
| 4032 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4033 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4034 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4035 | |
| 4036 | trans.reset(); |
| 4037 | session->CloseAllConnections(); |
| 4038 | } |
| 4039 | |
| 4040 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4041 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4042 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4043 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4044 | HttpRequestInfo request; |
| 4045 | request.method = "GET"; |
| 4046 | request.url = GURL("https://www.example.org/"); |
| 4047 | |
| 4048 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4049 | session_deps_.proxy_resolution_service = |
| 4050 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4051 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4052 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4053 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4054 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4055 | mock_handler->set_allows_default_credentials(true); |
| 4056 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4057 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4058 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4059 | |
| 4060 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4061 | NetLog net_log; |
| 4062 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4063 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4064 | |
| 4065 | // Should try to establish tunnel. |
| 4066 | MockWrite data_writes1[] = { |
| 4067 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4068 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4069 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4070 | |
| 4071 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4072 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4073 | "Proxy-Connection: keep-alive\r\n" |
| 4074 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4075 | }; |
| 4076 | |
| 4077 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4078 | // connection. |
| 4079 | MockRead data_reads1[] = { |
| 4080 | // No credentials. |
| 4081 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4082 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4083 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4084 | }; |
| 4085 | |
| 4086 | // Since the first connection was closed, need to establish another once given |
| 4087 | // credentials. |
| 4088 | MockWrite data_writes2[] = { |
| 4089 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4090 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4091 | "Proxy-Connection: keep-alive\r\n" |
| 4092 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4093 | |
| 4094 | MockWrite("GET / HTTP/1.1\r\n" |
| 4095 | "Host: www.example.org\r\n" |
| 4096 | "Connection: keep-alive\r\n\r\n"), |
| 4097 | }; |
| 4098 | |
| 4099 | MockRead data_reads2[] = { |
| 4100 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4101 | |
| 4102 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4103 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4104 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4105 | MockRead(SYNCHRONOUS, "hello"), |
| 4106 | }; |
| 4107 | |
| 4108 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4109 | data_writes1, arraysize(data_writes1)); |
| 4110 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4111 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4112 | data_writes2, arraysize(data_writes2)); |
| 4113 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4114 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4116 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4117 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4118 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4119 | |
| 4120 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4121 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4122 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4123 | |
| 4124 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4125 | ASSERT_TRUE(response); |
| 4126 | ASSERT_TRUE(response->headers); |
| 4127 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4128 | EXPECT_EQ(407, response->headers->response_code()); |
| 4129 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4130 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4131 | EXPECT_FALSE(response->auth_challenge); |
| 4132 | |
| 4133 | LoadTimingInfo load_timing_info; |
| 4134 | // CONNECT requests and responses are handled at the connect job level, so |
| 4135 | // the transaction does not yet have a connection. |
| 4136 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4137 | |
| 4138 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4139 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4140 | |
| 4141 | response = trans->GetResponseInfo(); |
| 4142 | ASSERT_TRUE(response); |
| 4143 | ASSERT_TRUE(response->headers); |
| 4144 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4145 | EXPECT_EQ(200, response->headers->response_code()); |
| 4146 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4147 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4148 | |
| 4149 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4150 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | |
| 4152 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4153 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4154 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4155 | |
| 4156 | trans.reset(); |
| 4157 | session->CloseAllConnections(); |
| 4158 | } |
| 4159 | |
| 4160 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4161 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4162 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4163 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4164 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4165 | HttpRequestInfo request; |
| 4166 | request.method = "GET"; |
| 4167 | request.url = GURL("https://www.example.org/"); |
| 4168 | |
| 4169 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4170 | session_deps_.proxy_resolution_service = |
| 4171 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4172 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4173 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4174 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4175 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4176 | mock_handler->set_allows_default_credentials(true); |
| 4177 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4178 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4179 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4180 | |
| 4181 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4182 | NetLog net_log; |
| 4183 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4184 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4185 | |
| 4186 | // Should try to establish tunnel. |
| 4187 | MockWrite data_writes1[] = { |
| 4188 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4189 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4190 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4191 | |
| 4192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4193 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4194 | "Proxy-Connection: keep-alive\r\n" |
| 4195 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4196 | }; |
| 4197 | |
| 4198 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4199 | // second request is sent. |
| 4200 | MockRead data_reads1[] = { |
| 4201 | // No credentials. |
| 4202 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4203 | MockRead("Content-Length: 0\r\n"), |
| 4204 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4205 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4206 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4207 | }; |
| 4208 | |
| 4209 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4210 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4211 | // request. |
| 4212 | MockWrite data_writes2[] = { |
| 4213 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4214 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4215 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4216 | }; |
| 4217 | |
| 4218 | // The proxy, having had more than enough of us, just hangs up. |
| 4219 | MockRead data_reads2[] = { |
| 4220 | // No credentials. |
| 4221 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4222 | }; |
| 4223 | |
| 4224 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4225 | data_writes1, arraysize(data_writes1)); |
| 4226 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4227 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4228 | data_writes2, arraysize(data_writes2)); |
| 4229 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4230 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4231 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4232 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4233 | |
| 4234 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4235 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4236 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4237 | |
| 4238 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4239 | ASSERT_TRUE(response); |
| 4240 | ASSERT_TRUE(response->headers); |
| 4241 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4242 | EXPECT_EQ(407, response->headers->response_code()); |
| 4243 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4244 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4245 | EXPECT_FALSE(response->auth_challenge); |
| 4246 | |
| 4247 | LoadTimingInfo load_timing_info; |
| 4248 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4249 | |
| 4250 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4251 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4252 | |
| 4253 | trans.reset(); |
| 4254 | session->CloseAllConnections(); |
| 4255 | } |
| 4256 | |
| 4257 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4258 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4259 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4260 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4262 | HttpRequestInfo request; |
| 4263 | request.method = "GET"; |
| 4264 | request.url = GURL("https://www.example.org/"); |
| 4265 | |
| 4266 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4267 | session_deps_.proxy_resolution_service = |
| 4268 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4269 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4270 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4271 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4272 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4273 | mock_handler->set_allows_default_credentials(true); |
| 4274 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4275 | HttpAuth::AUTH_PROXY); |
| 4276 | // Add another handler for the second challenge. It supports default |
| 4277 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4278 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4279 | mock_handler->set_allows_default_credentials(true); |
| 4280 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4281 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4282 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4283 | |
| 4284 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4285 | NetLog net_log; |
| 4286 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4287 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4288 | |
| 4289 | // Should try to establish tunnel. |
| 4290 | MockWrite data_writes1[] = { |
| 4291 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4292 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4293 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4294 | }; |
| 4295 | |
| 4296 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4297 | // connection. |
| 4298 | MockRead data_reads1[] = { |
| 4299 | // No credentials. |
| 4300 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4301 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4302 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4303 | }; |
| 4304 | |
| 4305 | // Since the first connection was closed, need to establish another once given |
| 4306 | // credentials. |
| 4307 | MockWrite data_writes2[] = { |
| 4308 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4309 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4310 | "Proxy-Connection: keep-alive\r\n" |
| 4311 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4312 | }; |
| 4313 | |
| 4314 | MockRead data_reads2[] = { |
| 4315 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4316 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4317 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 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 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4328 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4329 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4330 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4331 | |
| 4332 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4333 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4334 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4335 | |
| 4336 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4337 | ASSERT_TRUE(response); |
| 4338 | ASSERT_TRUE(response->headers); |
| 4339 | EXPECT_EQ(407, response->headers->response_code()); |
| 4340 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4341 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4342 | EXPECT_FALSE(response->auth_challenge); |
| 4343 | |
| 4344 | LoadTimingInfo load_timing_info; |
| 4345 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4346 | |
| 4347 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4348 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4349 | response = trans->GetResponseInfo(); |
| 4350 | ASSERT_TRUE(response); |
| 4351 | ASSERT_TRUE(response->headers); |
| 4352 | EXPECT_EQ(407, response->headers->response_code()); |
| 4353 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4354 | EXPECT_TRUE(response->auth_challenge); |
| 4355 | |
| 4356 | trans.reset(); |
| 4357 | session->CloseAllConnections(); |
| 4358 | } |
| 4359 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4360 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4361 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4362 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4363 | // authentication handshake can continue with the same scheme but with a |
| 4364 | // different identity. |
| 4365 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4366 | HttpRequestInfo request; |
| 4367 | request.method = "GET"; |
| 4368 | request.url = GURL("http://www.example.org/"); |
| 4369 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4370 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4371 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4372 | |
| 4373 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4374 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4375 | mock_handler->set_allows_default_credentials(true); |
| 4376 | mock_handler->set_allows_explicit_credentials(true); |
| 4377 | mock_handler->set_connection_based(true); |
| 4378 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4379 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4380 | HttpAuth::AUTH_SERVER); |
| 4381 | |
| 4382 | // Add another handler for the second challenge. It supports default |
| 4383 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4384 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4385 | mock_handler->set_allows_default_credentials(true); |
| 4386 | mock_handler->set_allows_explicit_credentials(true); |
| 4387 | mock_handler->set_connection_based(true); |
| 4388 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4389 | HttpAuth::AUTH_SERVER); |
| 4390 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4391 | |
| 4392 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4393 | |
| 4394 | MockWrite data_writes1[] = { |
| 4395 | MockWrite("GET / HTTP/1.1\r\n" |
| 4396 | "Host: www.example.org\r\n" |
| 4397 | "Connection: keep-alive\r\n\r\n"), |
| 4398 | }; |
| 4399 | |
| 4400 | MockRead data_reads1[] = { |
| 4401 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4402 | "WWW-Authenticate: Mock\r\n" |
| 4403 | "Connection: keep-alive\r\n\r\n"), |
| 4404 | }; |
| 4405 | |
| 4406 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4407 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4408 | // transaction procceds without an authorization header. |
| 4409 | MockWrite data_writes2[] = { |
| 4410 | MockWrite("GET / HTTP/1.1\r\n" |
| 4411 | "Host: www.example.org\r\n" |
| 4412 | "Connection: keep-alive\r\n\r\n"), |
| 4413 | }; |
| 4414 | |
| 4415 | MockRead data_reads2[] = { |
| 4416 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4417 | "WWW-Authenticate: Mock\r\n" |
| 4418 | "Connection: keep-alive\r\n\r\n"), |
| 4419 | }; |
| 4420 | |
| 4421 | MockWrite data_writes3[] = { |
| 4422 | MockWrite("GET / HTTP/1.1\r\n" |
| 4423 | "Host: www.example.org\r\n" |
| 4424 | "Connection: keep-alive\r\n" |
| 4425 | "Authorization: auth_token\r\n\r\n"), |
| 4426 | }; |
| 4427 | |
| 4428 | MockRead data_reads3[] = { |
| 4429 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4430 | "Content-Length: 5\r\n" |
| 4431 | "Content-Type: text/plain\r\n" |
| 4432 | "Connection: keep-alive\r\n\r\n" |
| 4433 | "Hello"), |
| 4434 | }; |
| 4435 | |
| 4436 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4437 | data_writes1, arraysize(data_writes1)); |
| 4438 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4439 | |
| 4440 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4441 | data_writes2, arraysize(data_writes2)); |
| 4442 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4443 | |
| 4444 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4445 | data_writes3, arraysize(data_writes3)); |
| 4446 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4447 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4448 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4449 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4450 | |
| 4451 | TestCompletionCallback callback; |
| 4452 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4453 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4454 | |
| 4455 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4456 | ASSERT_TRUE(response); |
| 4457 | ASSERT_TRUE(response->headers); |
| 4458 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4459 | |
| 4460 | // The following three tests assert that an authentication challenge was |
| 4461 | // received and that the stack is ready to respond to the challenge using |
| 4462 | // ambient credentials. |
| 4463 | EXPECT_EQ(401, response->headers->response_code()); |
| 4464 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4465 | EXPECT_FALSE(response->auth_challenge); |
| 4466 | |
| 4467 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4468 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4469 | response = trans->GetResponseInfo(); |
| 4470 | ASSERT_TRUE(response); |
| 4471 | ASSERT_TRUE(response->headers); |
| 4472 | |
| 4473 | // The following three tests assert that an authentication challenge was |
| 4474 | // received and that the stack needs explicit credentials before it is ready |
| 4475 | // to respond to the challenge. |
| 4476 | EXPECT_EQ(401, response->headers->response_code()); |
| 4477 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4478 | EXPECT_TRUE(response->auth_challenge); |
| 4479 | |
| 4480 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4481 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4482 | response = trans->GetResponseInfo(); |
| 4483 | ASSERT_TRUE(response); |
| 4484 | ASSERT_TRUE(response->headers); |
| 4485 | EXPECT_EQ(200, response->headers->response_code()); |
| 4486 | |
| 4487 | trans.reset(); |
| 4488 | session->CloseAllConnections(); |
| 4489 | } |
| 4490 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4491 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4492 | // schemes, based on the path of the URL being requests. |
| 4493 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4494 | public: |
| 4495 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4496 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4497 | |
| 4498 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4499 | |
| 4500 | static HostPortPair ProxyHostPortPair() { |
| 4501 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4502 | } |
| 4503 | |
| 4504 | // ProxyResolver implementation. |
| 4505 | int GetProxyForURL(const GURL& url, |
| 4506 | ProxyInfo* results, |
| 4507 | const CompletionCallback& callback, |
| 4508 | std::unique_ptr<Request>* request, |
| 4509 | const NetLogWithSource& /*net_log*/) override { |
| 4510 | *results = ProxyInfo(); |
| 4511 | if (url.path() == "/socks4") { |
| 4512 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4513 | return OK; |
| 4514 | } |
| 4515 | if (url.path() == "/socks5") { |
| 4516 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4517 | return OK; |
| 4518 | } |
| 4519 | if (url.path() == "/http") { |
| 4520 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4521 | return OK; |
| 4522 | } |
| 4523 | if (url.path() == "/https") { |
| 4524 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4525 | return OK; |
| 4526 | } |
| 4527 | NOTREACHED(); |
| 4528 | return ERR_NOT_IMPLEMENTED; |
| 4529 | } |
| 4530 | |
| 4531 | private: |
| 4532 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4533 | }; |
| 4534 | |
| 4535 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4536 | : public ProxyResolverFactory { |
| 4537 | public: |
| 4538 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4539 | : ProxyResolverFactory(false) {} |
| 4540 | |
| 4541 | int CreateProxyResolver( |
| 4542 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 4543 | std::unique_ptr<ProxyResolver>* resolver, |
| 4544 | const CompletionCallback& callback, |
| 4545 | std::unique_ptr<Request>* request) override { |
| 4546 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4547 | return OK; |
| 4548 | } |
| 4549 | |
| 4550 | private: |
| 4551 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4552 | }; |
| 4553 | |
| 4554 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4555 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4556 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4557 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4558 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4559 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4560 | std::make_unique<ProxyConfigServiceFixed>( |
| 4561 | ProxyConfig::CreateAutoDetect()), |
| 4562 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4563 | nullptr); |
| 4564 | |
| 4565 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4566 | |
| 4567 | MockWrite socks_writes[] = { |
| 4568 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4569 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4570 | MockWrite(SYNCHRONOUS, |
| 4571 | "GET /socks4 HTTP/1.1\r\n" |
| 4572 | "Host: test\r\n" |
| 4573 | "Connection: keep-alive\r\n\r\n"), |
| 4574 | }; |
| 4575 | MockRead socks_reads[] = { |
| 4576 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4577 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4578 | "Connection: keep-alive\r\n" |
| 4579 | "Content-Length: 15\r\n\r\n" |
| 4580 | "SOCKS4 Response"), |
| 4581 | }; |
| 4582 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4583 | socks_writes, arraysize(socks_writes)); |
| 4584 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4585 | |
| 4586 | const char kSOCKS5Request[] = { |
| 4587 | 0x05, // Version |
| 4588 | 0x01, // Command (CONNECT) |
| 4589 | 0x00, // Reserved |
| 4590 | 0x03, // Address type (DOMAINNAME) |
| 4591 | 0x04, // Length of domain (4) |
| 4592 | 't', 'e', 's', 't', // Domain string |
| 4593 | 0x00, 0x50, // 16-bit port (80) |
| 4594 | }; |
| 4595 | MockWrite socks5_writes[] = { |
| 4596 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4597 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4598 | MockWrite(SYNCHRONOUS, |
| 4599 | "GET /socks5 HTTP/1.1\r\n" |
| 4600 | "Host: test\r\n" |
| 4601 | "Connection: keep-alive\r\n\r\n"), |
| 4602 | }; |
| 4603 | MockRead socks5_reads[] = { |
| 4604 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4605 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4606 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4607 | "Connection: keep-alive\r\n" |
| 4608 | "Content-Length: 15\r\n\r\n" |
| 4609 | "SOCKS5 Response"), |
| 4610 | }; |
| 4611 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4612 | socks5_writes, arraysize(socks5_writes)); |
| 4613 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4614 | |
| 4615 | MockWrite http_writes[] = { |
| 4616 | MockWrite(SYNCHRONOUS, |
| 4617 | "GET http://test/http HTTP/1.1\r\n" |
| 4618 | "Host: test\r\n" |
| 4619 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4620 | }; |
| 4621 | MockRead http_reads[] = { |
| 4622 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4623 | "Proxy-Connection: keep-alive\r\n" |
| 4624 | "Content-Length: 13\r\n\r\n" |
| 4625 | "HTTP Response"), |
| 4626 | }; |
| 4627 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4628 | http_writes, arraysize(http_writes)); |
| 4629 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4630 | |
| 4631 | MockWrite https_writes[] = { |
| 4632 | MockWrite(SYNCHRONOUS, |
| 4633 | "GET http://test/https HTTP/1.1\r\n" |
| 4634 | "Host: test\r\n" |
| 4635 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4636 | }; |
| 4637 | MockRead https_reads[] = { |
| 4638 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4639 | "Proxy-Connection: keep-alive\r\n" |
| 4640 | "Content-Length: 14\r\n\r\n" |
| 4641 | "HTTPS Response"), |
| 4642 | }; |
| 4643 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4644 | https_writes, arraysize(https_writes)); |
| 4645 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4646 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4647 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4648 | |
| 4649 | struct TestCase { |
| 4650 | GURL url; |
| 4651 | std::string expected_response; |
| 4652 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4653 | // after the test. |
| 4654 | int expected_idle_socks_sockets; |
| 4655 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4656 | // the test. |
| 4657 | int expected_idle_http_sockets; |
| 4658 | } const kTestCases[] = { |
| 4659 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4660 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4661 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4662 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4663 | }; |
| 4664 | |
| 4665 | for (const auto& test_case : kTestCases) { |
| 4666 | HttpRequestInfo request; |
| 4667 | request.method = "GET"; |
| 4668 | request.url = test_case.url; |
| 4669 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4670 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4671 | session.get()); |
| 4672 | TestCompletionCallback callback; |
| 4673 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4674 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4675 | |
| 4676 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4677 | ASSERT_TRUE(response); |
| 4678 | ASSERT_TRUE(response->headers); |
| 4679 | EXPECT_EQ(200, response->headers->response_code()); |
| 4680 | std::string response_data; |
| 4681 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4682 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4683 | |
| 4684 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4685 | // the next requests. |
| 4686 | trans.reset(); |
| 4687 | base::RunLoop().RunUntilIdle(); |
| 4688 | |
| 4689 | // Check the number of idle sockets in the pool, to make sure that used |
| 4690 | // sockets are indeed being returned to the socket pool. If each request |
| 4691 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4692 | // pass. |
| 4693 | EXPECT_EQ( |
| 4694 | test_case.expected_idle_socks_sockets, |
| 4695 | session |
| 4696 | ->GetSocketPoolForSOCKSProxy( |
| 4697 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4698 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4699 | ->IdleSocketCount()); |
| 4700 | EXPECT_EQ( |
| 4701 | test_case.expected_idle_http_sockets, |
| 4702 | session |
| 4703 | ->GetSocketPoolForHTTPProxy( |
| 4704 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4705 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4706 | ->IdleSocketCount()); |
| 4707 | } |
| 4708 | } |
| 4709 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4710 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4711 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4712 | HttpRequestInfo request1; |
| 4713 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4714 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4715 | |
| 4716 | HttpRequestInfo request2; |
| 4717 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4718 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4719 | |
| 4720 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4721 | session_deps_.proxy_resolution_service = |
| 4722 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4723 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4724 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4725 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4726 | |
| 4727 | // Since we have proxy, should try to establish tunnel. |
| 4728 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4729 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4730 | "Host: www.example.org:443\r\n" |
| 4731 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4732 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4733 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4734 | "Host: www.example.org\r\n" |
| 4735 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4736 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4737 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4738 | "Host: www.example.org\r\n" |
| 4739 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4740 | }; |
| 4741 | |
| 4742 | // The proxy responds to the connect with a 407, using a persistent |
| 4743 | // connection. |
| 4744 | MockRead data_reads1[] = { |
| 4745 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4746 | |
| 4747 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4748 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4749 | MockRead(SYNCHRONOUS, "1"), |
| 4750 | |
| 4751 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4752 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4753 | MockRead(SYNCHRONOUS, "22"), |
| 4754 | }; |
| 4755 | |
| 4756 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4757 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4758 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4759 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4761 | |
| 4762 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4763 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4764 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4765 | |
| 4766 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4768 | |
| 4769 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4770 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4771 | |
| 4772 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4773 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4774 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4775 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4776 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4777 | |
| 4778 | LoadTimingInfo load_timing_info1; |
| 4779 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4780 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4781 | |
| 4782 | trans1.reset(); |
| 4783 | |
| 4784 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4785 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4787 | |
| 4788 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4790 | |
| 4791 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4792 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4793 | |
| 4794 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4795 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4796 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4797 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4798 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4799 | |
| 4800 | LoadTimingInfo load_timing_info2; |
| 4801 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4802 | TestLoadTimingReused(load_timing_info2); |
| 4803 | |
| 4804 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4805 | |
| 4806 | trans2.reset(); |
| 4807 | session->CloseAllConnections(); |
| 4808 | } |
| 4809 | |
| 4810 | // 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] | 4811 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4812 | HttpRequestInfo request1; |
| 4813 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4814 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4815 | |
| 4816 | HttpRequestInfo request2; |
| 4817 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4818 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4819 | |
| 4820 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4821 | session_deps_.proxy_resolution_service = |
| 4822 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4823 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4824 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4826 | |
| 4827 | // Since we have proxy, should try to establish tunnel. |
| 4828 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4829 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4830 | "Host: www.example.org:443\r\n" |
| 4831 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4832 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4833 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4834 | "Host: www.example.org\r\n" |
| 4835 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4836 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4837 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4838 | "Host: www.example.org\r\n" |
| 4839 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4840 | }; |
| 4841 | |
| 4842 | // The proxy responds to the connect with a 407, using a persistent |
| 4843 | // connection. |
| 4844 | MockRead data_reads1[] = { |
| 4845 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4846 | |
| 4847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4848 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4849 | MockRead(SYNCHRONOUS, "1"), |
| 4850 | |
| 4851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4852 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4853 | MockRead(SYNCHRONOUS, "22"), |
| 4854 | }; |
| 4855 | |
| 4856 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4857 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4858 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4859 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4860 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4861 | |
| 4862 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4863 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4864 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4865 | |
| 4866 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4867 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4868 | |
| 4869 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4870 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4871 | |
| 4872 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4873 | ASSERT_TRUE(response1); |
| 4874 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4875 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4876 | |
| 4877 | LoadTimingInfo load_timing_info1; |
| 4878 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4879 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4880 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4881 | |
| 4882 | trans1.reset(); |
| 4883 | |
| 4884 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4885 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4886 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4887 | |
| 4888 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4889 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4890 | |
| 4891 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4893 | |
| 4894 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4895 | ASSERT_TRUE(response2); |
| 4896 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4897 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4898 | |
| 4899 | LoadTimingInfo load_timing_info2; |
| 4900 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4901 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4902 | |
| 4903 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4904 | |
| 4905 | trans2.reset(); |
| 4906 | session->CloseAllConnections(); |
| 4907 | } |
| 4908 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4909 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4910 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4911 | HttpRequestInfo request; |
| 4912 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4913 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4914 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4915 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4916 | session_deps_.proxy_resolution_service = |
| 4917 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4918 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4919 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4921 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4922 | // Since we have proxy, should use full url |
| 4923 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4924 | MockWrite( |
| 4925 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4926 | "Host: www.example.org\r\n" |
| 4927 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4928 | }; |
| 4929 | |
| 4930 | MockRead data_reads1[] = { |
| 4931 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4932 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4933 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4934 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4935 | }; |
| 4936 | |
| 4937 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4938 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4939 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4940 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4941 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4943 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4947 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4949 | |
| 4950 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4951 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4952 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4953 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4954 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4955 | TestLoadTimingNotReused(load_timing_info, |
| 4956 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4958 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4959 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4960 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4961 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4962 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4963 | EXPECT_EQ(200, response->headers->response_code()); |
| 4964 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4965 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4966 | |
| 4967 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4968 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4969 | } |
| 4970 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4971 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4972 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4973 | HttpRequestInfo request; |
| 4974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4975 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4976 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4977 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4978 | session_deps_.proxy_resolution_service = |
| 4979 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4980 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4981 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4983 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4984 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4985 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4986 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4987 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4988 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4989 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4990 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4991 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4992 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4993 | }; |
| 4994 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4995 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4996 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4997 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4998 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4999 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5000 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5002 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5003 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5007 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5009 | |
| 5010 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5011 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5012 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5013 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5014 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5015 | TestLoadTimingNotReused(load_timing_info, |
| 5016 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5018 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5019 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5020 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5021 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5022 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5023 | |
| 5024 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5025 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5026 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5027 | } |
| 5028 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5029 | // Verifies that a session which races and wins against the owning transaction |
| 5030 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5031 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5032 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5033 | HttpRequestInfo request; |
| 5034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5035 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5036 | |
| 5037 | // Configure SPDY proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5038 | session_deps_.proxy_resolution_service = |
| 5039 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5040 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5041 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5043 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5044 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5045 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5046 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5047 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5048 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5049 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5050 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5051 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5052 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5053 | }; |
| 5054 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5055 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5056 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5057 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5058 | |
| 5059 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5060 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5062 | |
| 5063 | TestCompletionCallback callback1; |
| 5064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5066 | |
| 5067 | // Stall the hostname resolution begun by the transaction. |
| 5068 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5069 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5071 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5073 | |
| 5074 | // Race a session to the proxy, which completes first. |
| 5075 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5076 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5077 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5078 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5079 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5080 | |
| 5081 | // Unstall the resolution begun by the transaction. |
| 5082 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5083 | session_deps_.host_resolver->ResolveAllPending(); |
| 5084 | |
| 5085 | EXPECT_FALSE(callback1.have_result()); |
| 5086 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5089 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5090 | ASSERT_TRUE(response); |
| 5091 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5092 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5093 | |
| 5094 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5095 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5096 | EXPECT_EQ(kUploadData, response_data); |
| 5097 | } |
| 5098 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5099 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5100 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5101 | HttpRequestInfo request; |
| 5102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5103 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5104 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5105 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5106 | session_deps_.proxy_resolution_service = |
| 5107 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5108 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5109 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5110 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5111 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5112 | // The first request will be a bare GET, the second request will be a |
| 5113 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5114 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5115 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5116 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5117 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5118 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5119 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5120 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5121 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5122 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 5123 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5124 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5125 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5126 | }; |
| 5127 | |
| 5128 | // The first response is a 407 proxy authentication challenge, and the second |
| 5129 | // response will be a 200 response since the second request includes a valid |
| 5130 | // Authorization header. |
| 5131 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5132 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5133 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5134 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5135 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5136 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5137 | SpdySerializedFrame body_authentication( |
| 5138 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5139 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5140 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5141 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5142 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5143 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5144 | CreateMockRead(resp_data, 4), |
| 5145 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5146 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5147 | }; |
| 5148 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5149 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5150 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5152 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5153 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5154 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5155 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5157 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5161 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5163 | |
| 5164 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5165 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5167 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5168 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5169 | ASSERT_TRUE(response); |
| 5170 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5171 | EXPECT_EQ(407, response->headers->response_code()); |
| 5172 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5173 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5175 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5177 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5178 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5179 | |
| 5180 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5181 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5182 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5183 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5184 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5185 | ASSERT_TRUE(response_restart); |
| 5186 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5187 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5188 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5189 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5190 | } |
| 5191 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5192 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5193 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5194 | HttpRequestInfo request; |
| 5195 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5196 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5197 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5198 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5199 | session_deps_.proxy_resolution_service = |
| 5200 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5201 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5202 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5203 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5205 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5206 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5207 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5208 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5209 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5210 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5211 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5212 | const char get[] = |
| 5213 | "GET / HTTP/1.1\r\n" |
| 5214 | "Host: www.example.org\r\n" |
| 5215 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5216 | SpdySerializedFrame wrapped_get( |
| 5217 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5218 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5219 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5220 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5221 | SpdySerializedFrame wrapped_get_resp( |
| 5222 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 5223 | SpdySerializedFrame wrapped_body( |
| 5224 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 5225 | SpdySerializedFrame window_update( |
| 5226 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5227 | |
| 5228 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5229 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5230 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5231 | }; |
| 5232 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5233 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5234 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5235 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5236 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5237 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5238 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5239 | }; |
| 5240 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5241 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5242 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5243 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5244 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5245 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5246 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5248 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5251 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5253 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5255 | |
| 5256 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5257 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5258 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5259 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5260 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5261 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5263 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5264 | ASSERT_TRUE(response); |
| 5265 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5266 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5267 | |
| 5268 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5269 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5270 | EXPECT_EQ("1234567890", response_data); |
| 5271 | } |
| 5272 | |
| 5273 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5274 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5275 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5276 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5277 | HttpRequestInfo request; |
| 5278 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5279 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5280 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5281 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5282 | session_deps_.proxy_resolution_service = |
| 5283 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5284 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5285 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5288 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5289 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5290 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5291 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5292 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5293 | // fetch https://www.example.org/ via SPDY |
| 5294 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5295 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5296 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5297 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5298 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5299 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5300 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5301 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5302 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5303 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5304 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5305 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5306 | SpdySerializedFrame window_update_get_resp( |
| 5307 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5308 | SpdySerializedFrame window_update_body( |
| 5309 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5310 | |
| 5311 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5312 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5313 | CreateMockWrite(window_update_get_resp, 6), |
| 5314 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5315 | }; |
| 5316 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5317 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5318 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5319 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5320 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5321 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5322 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5323 | }; |
| 5324 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5325 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5326 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5327 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5328 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5329 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5330 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5331 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5332 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5333 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5336 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5338 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5339 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5340 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5341 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5342 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5343 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5344 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5345 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5346 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5347 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5348 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5349 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5350 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5352 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5353 | ASSERT_TRUE(response); |
| 5354 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5355 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5356 | |
| 5357 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5358 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5359 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5360 | } |
| 5361 | |
| 5362 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5363 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5364 | HttpRequestInfo request; |
| 5365 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5366 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5367 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5368 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5369 | session_deps_.proxy_resolution_service = |
| 5370 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5371 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5372 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5376 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5377 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5378 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5379 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5380 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5381 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5382 | |
| 5383 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5384 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5385 | }; |
| 5386 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5387 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5388 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5389 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5390 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5391 | }; |
| 5392 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5393 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5394 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5395 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5396 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5397 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5398 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5400 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5401 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5404 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5406 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5408 | |
| 5409 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5410 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5411 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5412 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5413 | } |
| 5414 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5415 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5416 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5417 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5418 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5419 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5420 | session_deps_.proxy_resolution_service = |
| 5421 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5422 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5423 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5424 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5425 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5426 | |
| 5427 | HttpRequestInfo request1; |
| 5428 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5429 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5430 | request1.load_flags = 0; |
| 5431 | |
| 5432 | HttpRequestInfo request2; |
| 5433 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5434 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5435 | request2.load_flags = 0; |
| 5436 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5437 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5438 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5439 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5440 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5441 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5442 | // Fetch https://www.example.org/ via HTTP. |
| 5443 | const char get1[] = |
| 5444 | "GET / HTTP/1.1\r\n" |
| 5445 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5446 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5447 | SpdySerializedFrame wrapped_get1( |
| 5448 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5449 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5450 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5451 | SpdySerializedFrame wrapped_get_resp1( |
| 5452 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5453 | SpdySerializedFrame wrapped_body1( |
| 5454 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5455 | SpdySerializedFrame window_update( |
| 5456 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5457 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5458 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5459 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5460 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5461 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5462 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5463 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5464 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5465 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5466 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5467 | // Fetch https://mail.example.org/ via HTTP. |
| 5468 | const char get2[] = |
| 5469 | "GET / HTTP/1.1\r\n" |
| 5470 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5471 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5472 | SpdySerializedFrame wrapped_get2( |
| 5473 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5474 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5475 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5476 | SpdySerializedFrame wrapped_get_resp2( |
| 5477 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5478 | SpdySerializedFrame wrapped_body2( |
| 5479 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5480 | |
| 5481 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5482 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5483 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5484 | }; |
| 5485 | |
| 5486 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5487 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5488 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5489 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5490 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5491 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5492 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5493 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5494 | }; |
| 5495 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5496 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5497 | arraysize(spdy_writes)); |
| 5498 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5499 | |
| 5500 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5501 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5503 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5505 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5507 | |
| 5508 | TestCompletionCallback callback; |
| 5509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5510 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5511 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5512 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5513 | |
| 5514 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5515 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5516 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5518 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5519 | ASSERT_TRUE(response); |
| 5520 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5521 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5522 | |
| 5523 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5524 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5525 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5526 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5528 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5529 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5530 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5531 | |
| 5532 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5533 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5534 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5535 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5536 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5537 | |
| 5538 | // The requests should have different IDs, since they each are using their own |
| 5539 | // separate stream. |
| 5540 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5542 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5543 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5544 | } |
| 5545 | |
| 5546 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5547 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5548 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5549 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5550 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5551 | session_deps_.proxy_resolution_service = |
| 5552 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5553 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5554 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5555 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5556 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5557 | |
| 5558 | HttpRequestInfo request1; |
| 5559 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5560 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5561 | request1.load_flags = 0; |
| 5562 | |
| 5563 | HttpRequestInfo request2; |
| 5564 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5565 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5566 | request2.load_flags = 0; |
| 5567 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5568 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5569 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5570 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5571 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5572 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5573 | // Fetch https://www.example.org/ via HTTP. |
| 5574 | const char get1[] = |
| 5575 | "GET / HTTP/1.1\r\n" |
| 5576 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5577 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5578 | SpdySerializedFrame wrapped_get1( |
| 5579 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5580 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5581 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5582 | SpdySerializedFrame wrapped_get_resp1( |
| 5583 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5584 | SpdySerializedFrame wrapped_body1( |
| 5585 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5586 | SpdySerializedFrame window_update( |
| 5587 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5588 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5589 | // Fetch https://www.example.org/2 via HTTP. |
| 5590 | const char get2[] = |
| 5591 | "GET /2 HTTP/1.1\r\n" |
| 5592 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5593 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5594 | SpdySerializedFrame wrapped_get2( |
| 5595 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5596 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5597 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5598 | SpdySerializedFrame wrapped_get_resp2( |
| 5599 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5600 | SpdySerializedFrame wrapped_body2( |
| 5601 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5602 | |
| 5603 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5604 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5605 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5606 | }; |
| 5607 | |
| 5608 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5609 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5610 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5611 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5612 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5613 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5614 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5615 | }; |
| 5616 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5617 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5618 | arraysize(spdy_writes)); |
| 5619 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5620 | |
| 5621 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5622 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5624 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5625 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5626 | |
| 5627 | TestCompletionCallback callback; |
| 5628 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5629 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5630 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5631 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5633 | |
| 5634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5635 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5636 | |
| 5637 | LoadTimingInfo load_timing_info; |
| 5638 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5639 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5640 | |
| 5641 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5642 | ASSERT_TRUE(response); |
| 5643 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5644 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5645 | |
| 5646 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5647 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5648 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5649 | trans.reset(); |
| 5650 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5651 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5652 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5653 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5655 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5656 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5657 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5658 | |
| 5659 | LoadTimingInfo load_timing_info2; |
| 5660 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5661 | TestLoadTimingReused(load_timing_info2); |
| 5662 | |
| 5663 | // The requests should have the same ID. |
| 5664 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5665 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5666 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5667 | } |
| 5668 | |
| 5669 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5670 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5671 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5672 | // Configure against https proxy server "proxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5673 | session_deps_.proxy_resolution_service = |
| 5674 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5675 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5676 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5677 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5678 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5679 | |
| 5680 | HttpRequestInfo request1; |
| 5681 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5682 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5683 | request1.load_flags = 0; |
| 5684 | |
| 5685 | HttpRequestInfo request2; |
| 5686 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5687 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5688 | request2.load_flags = 0; |
| 5689 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5690 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5691 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5692 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5693 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5694 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5695 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5696 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5697 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5698 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5699 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5700 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5701 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5702 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5703 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5704 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5705 | SpdySerializedFrame body2( |
| 5706 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5707 | |
| 5708 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5709 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5710 | }; |
| 5711 | |
| 5712 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5713 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5714 | CreateMockRead(body1, 2, ASYNC), |
| 5715 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5716 | CreateMockRead(body2, 5, ASYNC), |
| 5717 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5718 | }; |
| 5719 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5720 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5721 | arraysize(spdy_writes)); |
| 5722 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5723 | |
| 5724 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5725 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5727 | |
| 5728 | TestCompletionCallback callback; |
| 5729 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5730 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5731 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5732 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5733 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5734 | |
| 5735 | LoadTimingInfo load_timing_info; |
| 5736 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5737 | TestLoadTimingNotReused(load_timing_info, |
| 5738 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5739 | |
| 5740 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5741 | ASSERT_TRUE(response); |
| 5742 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5743 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5744 | |
| 5745 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5746 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5747 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5748 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5749 | // Delete the first request, so the second one can reuse the socket. |
| 5750 | trans.reset(); |
| 5751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5752 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5753 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5754 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5755 | |
| 5756 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5757 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5758 | TestLoadTimingReused(load_timing_info2); |
| 5759 | |
| 5760 | // The requests should have the same ID. |
| 5761 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5763 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5764 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5765 | } |
| 5766 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5767 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5768 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5769 | HttpRequestInfo request; |
| 5770 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5771 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5772 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5773 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5774 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5775 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5776 | session_deps_.proxy_resolution_service = |
| 5777 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5778 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5779 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5781 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5782 | // Since we have proxy, should use full url |
| 5783 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5784 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5785 | "Host: www.example.org\r\n" |
| 5786 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5788 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5789 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5790 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5791 | "Host: www.example.org\r\n" |
| 5792 | "Proxy-Connection: keep-alive\r\n" |
| 5793 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5794 | }; |
| 5795 | |
| 5796 | // The proxy responds to the GET with a 407, using a persistent |
| 5797 | // connection. |
| 5798 | MockRead data_reads1[] = { |
| 5799 | // No credentials. |
| 5800 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5801 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5802 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5803 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5804 | |
| 5805 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5806 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5807 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5808 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5809 | }; |
| 5810 | |
| 5811 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5812 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5814 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5815 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5819 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5821 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5823 | |
| 5824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5826 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5827 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5828 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5829 | TestLoadTimingNotReused(load_timing_info, |
| 5830 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5832 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5833 | ASSERT_TRUE(response); |
| 5834 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5835 | EXPECT_EQ(407, response->headers->response_code()); |
| 5836 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5837 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5838 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5839 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5841 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5843 | |
| 5844 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5845 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5846 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5847 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5848 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5849 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5850 | TestLoadTimingReused(load_timing_info); |
| 5851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5852 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5853 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5854 | |
| 5855 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5856 | EXPECT_EQ(200, response->headers->response_code()); |
| 5857 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5858 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5859 | |
| 5860 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5861 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5862 | } |
| 5863 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5864 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5865 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5866 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5867 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5868 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5869 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5870 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5871 | session_deps_.proxy_resolution_service = |
| 5872 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5874 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5875 | // Since we have proxy, should try to establish tunnel. |
| 5876 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5878 | "Host: www.example.org:443\r\n" |
| 5879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5880 | }; |
| 5881 | |
| 5882 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5883 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5884 | // No response body because the test stops reading here. |
| 5885 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5886 | }; |
| 5887 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5888 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5889 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5892 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5893 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5894 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5896 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5898 | |
| 5899 | rv = callback.WaitForResult(); |
| 5900 | EXPECT_EQ(expected_status, rv); |
| 5901 | } |
| 5902 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5903 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5904 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5905 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5906 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5907 | } |
| 5908 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5909 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5910 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5911 | } |
| 5912 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5913 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5914 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5915 | } |
| 5916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5917 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5918 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5919 | } |
| 5920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5921 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5922 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5923 | } |
| 5924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5925 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5926 | ConnectStatusHelper( |
| 5927 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5928 | } |
| 5929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5931 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5932 | } |
| 5933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5935 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5936 | } |
| 5937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5939 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5940 | } |
| 5941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5943 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5944 | } |
| 5945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5947 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5948 | } |
| 5949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5951 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5952 | } |
| 5953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5955 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5956 | } |
| 5957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5959 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5960 | } |
| 5961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5963 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5964 | } |
| 5965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5967 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5968 | } |
| 5969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5971 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5972 | } |
| 5973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5974 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5975 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5976 | } |
| 5977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5978 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5979 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5980 | } |
| 5981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5982 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5983 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5984 | } |
| 5985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5986 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5987 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5988 | } |
| 5989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5990 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5991 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5992 | } |
| 5993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5994 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5995 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5996 | } |
| 5997 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5998 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5999 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6000 | } |
| 6001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6002 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6003 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6004 | } |
| 6005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6006 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6007 | ConnectStatusHelperWithExpectedStatus( |
| 6008 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6009 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6010 | } |
| 6011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6012 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6013 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6014 | } |
| 6015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6016 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6017 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6018 | } |
| 6019 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6020 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6021 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6022 | } |
| 6023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6024 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6025 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6026 | } |
| 6027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6028 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6029 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6030 | } |
| 6031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6032 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6033 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6034 | } |
| 6035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6036 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6037 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6038 | } |
| 6039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6040 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6041 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6042 | } |
| 6043 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6044 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6045 | ConnectStatusHelper( |
| 6046 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6047 | } |
| 6048 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6049 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6050 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6051 | } |
| 6052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6054 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6055 | } |
| 6056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6057 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6058 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6059 | } |
| 6060 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6061 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6062 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6063 | } |
| 6064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6065 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6066 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6067 | } |
| 6068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6069 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6070 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6071 | } |
| 6072 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6073 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6074 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6075 | } |
| 6076 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6077 | // Test the flow when both the proxy server AND origin server require |
| 6078 | // authentication. Again, this uses basic auth for both since that is |
| 6079 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6080 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6081 | HttpRequestInfo request; |
| 6082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6083 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6084 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6085 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6086 | session_deps_.proxy_resolution_service = |
| 6087 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6089 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6091 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6092 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6093 | MockWrite( |
| 6094 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6095 | "Host: www.example.org\r\n" |
| 6096 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6097 | }; |
| 6098 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6099 | MockRead data_reads1[] = { |
| 6100 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6101 | // Give a couple authenticate options (only the middle one is actually |
| 6102 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6103 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6104 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6105 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6106 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6107 | // Large content-length -- won't matter, as connection will be reset. |
| 6108 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6109 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6110 | }; |
| 6111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6112 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6113 | // request we should be issuing -- the final header line contains the |
| 6114 | // proxy's credentials. |
| 6115 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6116 | MockWrite( |
| 6117 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6118 | "Host: www.example.org\r\n" |
| 6119 | "Proxy-Connection: keep-alive\r\n" |
| 6120 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6121 | }; |
| 6122 | |
| 6123 | // Now the proxy server lets the request pass through to origin server. |
| 6124 | // The origin server responds with a 401. |
| 6125 | MockRead data_reads2[] = { |
| 6126 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6127 | // Note: We are using the same realm-name as the proxy server. This is |
| 6128 | // completely valid, as realms are unique across hosts. |
| 6129 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6130 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6131 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6132 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6133 | }; |
| 6134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6135 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6136 | // the credentials for both the proxy and origin server. |
| 6137 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6138 | MockWrite( |
| 6139 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6140 | "Host: www.example.org\r\n" |
| 6141 | "Proxy-Connection: keep-alive\r\n" |
| 6142 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6143 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6144 | }; |
| 6145 | |
| 6146 | // Lastly we get the desired content. |
| 6147 | MockRead data_reads3[] = { |
| 6148 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6149 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6150 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6151 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6152 | }; |
| 6153 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6154 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6155 | data_writes1, arraysize(data_writes1)); |
| 6156 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6157 | data_writes2, arraysize(data_writes2)); |
| 6158 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6159 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6160 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6161 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6162 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6163 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6164 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6165 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6166 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6168 | |
| 6169 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6170 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6172 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6173 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6174 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6176 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6178 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6179 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6180 | |
| 6181 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6182 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6184 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6185 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6186 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6188 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6190 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6191 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6193 | |
| 6194 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6195 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6196 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6197 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6198 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6199 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6200 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6201 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6202 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6203 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6204 | // authorization headers. |
| 6205 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6206 | // The NTLM authentication unit tests are based on known test data from the |
| 6207 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6208 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6209 | // for the implementation and testing of the protocol. |
| 6210 | // |
| 6211 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6212 | |
| 6213 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6214 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6215 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6216 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6217 | request.url = GURL("https://server/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6218 | |
| 6219 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6220 | // to other auth schemes. |
| 6221 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6222 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6223 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6224 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6226 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6227 | // Generate the NTLM messages based on known test data. |
| 6228 | std::string negotiate_msg; |
| 6229 | std::string challenge_msg; |
| 6230 | std::string authenticate_msg; |
| 6231 | base::Base64Encode( |
| 6232 | base::StringPiece( |
| 6233 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6234 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6235 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6236 | base::Base64Encode( |
| 6237 | base::StringPiece( |
| 6238 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6239 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6240 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6241 | base::Base64Encode( |
| 6242 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6243 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6244 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6245 | arraysize( |
| 6246 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6247 | &authenticate_msg); |
| 6248 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6249 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6250 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6251 | "Host: server\r\n" |
| 6252 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6253 | }; |
| 6254 | |
| 6255 | MockRead data_reads1[] = { |
| 6256 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6257 | // Negotiate and NTLM are often requested together. However, we only want |
| 6258 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6259 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6260 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6261 | MockRead("Connection: close\r\n"), |
| 6262 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6263 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6264 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6265 | }; |
| 6266 | |
| 6267 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6268 | // After restarting with a null identity, this is the |
| 6269 | // request we should be issuing -- the final header line contains a Type |
| 6270 | // 1 message. |
| 6271 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6272 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6273 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6274 | "Authorization: NTLM "), |
| 6275 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6277 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6278 | // (using correct credentials). The second request continues on the |
| 6279 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6280 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6281 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6282 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6283 | "Authorization: NTLM "), |
| 6284 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6285 | }; |
| 6286 | |
| 6287 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6288 | // The origin server responds with a Type 2 message. |
| 6289 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6290 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6291 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6292 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6293 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6294 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6295 | // Lastly we get the desired content. |
| 6296 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6297 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6298 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6299 | }; |
| 6300 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6301 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6302 | data_writes1, arraysize(data_writes1)); |
| 6303 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6304 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6305 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6306 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6307 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6308 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6309 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6310 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6311 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6313 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6315 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6317 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6319 | |
| 6320 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6321 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6322 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6323 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6325 | const HttpResponseInfo* 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(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6329 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6330 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6331 | rv = trans.RestartWithAuth( |
| 6332 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6333 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6335 | |
| 6336 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6339 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6340 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6341 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6342 | ASSERT_TRUE(response); |
| 6343 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6344 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6345 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6347 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6349 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6350 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6351 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6352 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6353 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6354 | ASSERT_TRUE(response); |
| 6355 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6356 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6357 | |
| 6358 | std::string response_data; |
| 6359 | rv = ReadTransaction(&trans, &response_data); |
| 6360 | EXPECT_THAT(rv, IsOk()); |
| 6361 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6362 | |
| 6363 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6364 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6365 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6366 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6367 | } |
| 6368 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6369 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6370 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6371 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6372 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6373 | request.url = GURL("https://server/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6374 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6375 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6376 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6378 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6379 | // Generate the NTLM messages based on known test data. |
| 6380 | std::string negotiate_msg; |
| 6381 | std::string challenge_msg; |
| 6382 | std::string authenticate_msg; |
| 6383 | base::Base64Encode( |
| 6384 | base::StringPiece( |
| 6385 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6386 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6387 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6388 | base::Base64Encode( |
| 6389 | base::StringPiece( |
| 6390 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6391 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6392 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6393 | base::Base64Encode( |
| 6394 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6395 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6396 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6397 | arraysize( |
| 6398 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6399 | &authenticate_msg); |
| 6400 | |
| 6401 | // The authenticate message when |kWrongPassword| is sent. |
| 6402 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6403 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6404 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6405 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6406 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6407 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6408 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6409 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6410 | // Sanity check that it's the same length as the correct authenticate message |
| 6411 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6412 | ASSERT_EQ(authenticate_msg.length(), |
| 6413 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6414 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6415 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6416 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6417 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6418 | "Host: server\r\n" |
| 6419 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6420 | }; |
| 6421 | |
| 6422 | MockRead data_reads1[] = { |
| 6423 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6424 | // Negotiate and NTLM are often requested together. However, we only want |
| 6425 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6426 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6427 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6428 | MockRead("Connection: close\r\n"), |
| 6429 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6430 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6431 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6432 | }; |
| 6433 | |
| 6434 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6435 | // After restarting with a null identity, this is the |
| 6436 | // request we should be issuing -- the final header line contains a Type |
| 6437 | // 1 message. |
| 6438 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6439 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6440 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6441 | "Authorization: NTLM "), |
| 6442 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6444 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6445 | // (using incorrect credentials). The second request continues on the |
| 6446 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6447 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6448 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6449 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6450 | "Authorization: NTLM "), |
| 6451 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6452 | }; |
| 6453 | |
| 6454 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6455 | // The origin server responds with a Type 2 message. |
| 6456 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6457 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6458 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6459 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6460 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6461 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6462 | // Wrong password. |
| 6463 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6464 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6465 | MockRead("Content-Length: 42\r\n"), |
| 6466 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6467 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6468 | }; |
| 6469 | |
| 6470 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6471 | // After restarting with a null identity, this is the |
| 6472 | // request we should be issuing -- the final header line contains a Type |
| 6473 | // 1 message. |
| 6474 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6475 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6476 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6477 | "Authorization: NTLM "), |
| 6478 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6480 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6481 | // (the credentials for the origin server). The second request continues |
| 6482 | // on the same connection. |
| 6483 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6484 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6485 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6486 | "Authorization: NTLM "), |
| 6487 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6488 | }; |
| 6489 | |
| 6490 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6491 | // The origin server responds with a Type 2 message. |
| 6492 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6493 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6494 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6495 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6496 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6497 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6498 | // Lastly we get the desired content. |
| 6499 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6500 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6501 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6502 | }; |
| 6503 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6504 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6505 | data_writes1, arraysize(data_writes1)); |
| 6506 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6507 | data_writes2, arraysize(data_writes2)); |
| 6508 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6509 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6510 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6511 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6512 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6513 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6514 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6515 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6516 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6518 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6521 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6524 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6525 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6526 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6527 | |
| 6528 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6529 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6531 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6533 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6534 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6535 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6537 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6538 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6539 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6540 | rv = trans.RestartWithAuth( |
| 6541 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6542 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6544 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6545 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6546 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6548 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6549 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6550 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6552 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6553 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6554 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6556 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6557 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6558 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6560 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6561 | |
| 6562 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6563 | rv = trans.RestartWithAuth( |
| 6564 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6565 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6567 | |
| 6568 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6569 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6571 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6572 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6573 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6574 | |
| 6575 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6576 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6578 | |
| 6579 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6582 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6583 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6584 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6585 | |
| 6586 | std::string response_data; |
| 6587 | rv = ReadTransaction(&trans, &response_data); |
| 6588 | EXPECT_THAT(rv, IsOk()); |
| 6589 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6590 | |
| 6591 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6592 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6593 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6594 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6595 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6596 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6597 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6598 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6599 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6600 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6601 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6602 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6603 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6604 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6605 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6606 | |
| 6607 | HttpRequestInfo request; |
| 6608 | request.method = "GET"; |
| 6609 | request.url = GURL(kUrl); |
| 6610 | |
| 6611 | // First request without credentials. |
| 6612 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6613 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6614 | 1, std::move(request_headers0), LOWEST, true)); |
| 6615 | |
| 6616 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6617 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6618 | response_headers0["www-authenticate"] = "NTLM"; |
| 6619 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6620 | 1, std::move(response_headers0), true)); |
| 6621 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6622 | // Stream 1 is closed. |
| 6623 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6624 | |
| 6625 | // Generate the NTLM messages based on known test data. |
| 6626 | std::string negotiate_msg; |
| 6627 | std::string challenge_msg; |
| 6628 | std::string authenticate_msg; |
| 6629 | base::Base64Encode( |
| 6630 | base::StringPiece( |
| 6631 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6632 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6633 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6634 | base::Base64Encode( |
| 6635 | base::StringPiece( |
| 6636 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6637 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6638 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6639 | base::Base64Encode( |
| 6640 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6641 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6642 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6643 | arraysize( |
| 6644 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6645 | &authenticate_msg); |
| 6646 | |
| 6647 | // Retry with authorization header. |
| 6648 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6649 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6650 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6651 | 3, std::move(request_headers1), LOWEST, true)); |
| 6652 | |
| 6653 | SpdySerializedFrame rst( |
| 6654 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6655 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6656 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6657 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6658 | |
| 6659 | // Retry yet again using HTTP/1.1. |
| 6660 | MockWrite writes1[] = { |
| 6661 | // After restarting with a null identity, this is the |
| 6662 | // request we should be issuing -- the final header line contains a Type |
| 6663 | // 1 message. |
| 6664 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6665 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6666 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6667 | "Authorization: NTLM "), |
| 6668 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6669 | |
| 6670 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6671 | // (the credentials for the origin server). The second request continues |
| 6672 | // on the same connection. |
| 6673 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6674 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6675 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6676 | "Authorization: NTLM "), |
| 6677 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6678 | }; |
| 6679 | |
| 6680 | MockRead reads1[] = { |
| 6681 | // The origin server responds with a Type 2 message. |
| 6682 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6683 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6684 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6685 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6686 | MockRead("You are not authorized to view this page\r\n"), |
| 6687 | |
| 6688 | // Lastly we get the desired content. |
| 6689 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6690 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6691 | 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] | 6692 | }; |
| 6693 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6694 | arraysize(writes0)); |
| 6695 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6696 | arraysize(writes1)); |
| 6697 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6699 | |
| 6700 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6701 | ssl0.next_proto = kProtoHTTP2; |
| 6702 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6704 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6705 | |
| 6706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6708 | |
| 6709 | TestCompletionCallback callback1; |
| 6710 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6712 | |
| 6713 | rv = callback1.WaitForResult(); |
| 6714 | EXPECT_THAT(rv, IsOk()); |
| 6715 | |
| 6716 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6717 | |
| 6718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6719 | ASSERT_TRUE(response); |
| 6720 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6721 | |
| 6722 | TestCompletionCallback callback2; |
| 6723 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6724 | rv = trans.RestartWithAuth( |
| 6725 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6726 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6728 | |
| 6729 | rv = callback2.WaitForResult(); |
| 6730 | EXPECT_THAT(rv, IsOk()); |
| 6731 | |
| 6732 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6733 | |
| 6734 | response = trans.GetResponseInfo(); |
| 6735 | ASSERT_TRUE(response); |
| 6736 | EXPECT_FALSE(response->auth_challenge); |
| 6737 | |
| 6738 | TestCompletionCallback callback3; |
| 6739 | |
| 6740 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6742 | |
| 6743 | rv = callback3.WaitForResult(); |
| 6744 | EXPECT_THAT(rv, IsOk()); |
| 6745 | |
| 6746 | response = trans.GetResponseInfo(); |
| 6747 | ASSERT_TRUE(response); |
| 6748 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6749 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6750 | |
| 6751 | std::string response_data; |
| 6752 | rv = ReadTransaction(&trans, &response_data); |
| 6753 | EXPECT_THAT(rv, IsOk()); |
| 6754 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6755 | |
| 6756 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6757 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6758 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6759 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6760 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6761 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6762 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6763 | // Test reading a server response which has only headers, and no body. |
| 6764 | // After some maximum number of bytes is consumed, the transaction should |
| 6765 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6766 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6767 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6769 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6770 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6773 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6774 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6775 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6776 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6777 | |
| 6778 | MockRead data_reads[] = { |
| 6779 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6780 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6781 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6783 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6784 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6785 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6786 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6787 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6788 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6789 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6790 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6791 | |
| 6792 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6793 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6794 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6795 | |
| 6796 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6797 | // establish tunnel. |
| 6798 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6799 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6800 | HttpRequestInfo request; |
| 6801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6802 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6803 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6804 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 6805 | session_deps_.proxy_resolution_service = |
| 6806 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6809 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6810 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6811 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6812 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6813 | // Since we have proxy, should try to establish tunnel. |
| 6814 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6815 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6816 | "Host: www.example.org:443\r\n" |
| 6817 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6818 | }; |
| 6819 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6820 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6821 | // connection. Usually a proxy would return 501 (not implemented), |
| 6822 | // or 200 (tunnel established). |
| 6823 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6824 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6825 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6826 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6827 | }; |
| 6828 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6829 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6830 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6831 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6833 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6834 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6835 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6837 | |
| 6838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6839 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6840 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6841 | // Empty the current queue. This is necessary because idle sockets are |
| 6842 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6843 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6844 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6845 | // We now check to make sure the TCPClientSocket was not added back to |
| 6846 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6847 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6848 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6849 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6850 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6851 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6852 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6853 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6854 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6855 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6856 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6858 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6859 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6860 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6863 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6864 | MockRead data_reads[] = { |
| 6865 | // A part of the response body is received with the response headers. |
| 6866 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6867 | // The rest of the response body is received in two parts. |
| 6868 | MockRead("lo"), |
| 6869 | MockRead(" world"), |
| 6870 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6872 | }; |
| 6873 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6874 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6877 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6879 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6881 | |
| 6882 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6883 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6884 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6885 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6886 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6887 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6888 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6889 | std::string status_line = response->headers->GetStatusLine(); |
| 6890 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6891 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6892 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6893 | |
| 6894 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6895 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6896 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6897 | EXPECT_EQ("hello world", response_data); |
| 6898 | |
| 6899 | // Empty the current queue. This is necessary because idle sockets are |
| 6900 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6901 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6902 | |
| 6903 | // 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] | 6904 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6905 | } |
| 6906 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6907 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6908 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6909 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6910 | HttpRequestInfo request; |
| 6911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6912 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6913 | |
| 6914 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6915 | MockWrite( |
| 6916 | "GET / HTTP/1.1\r\n" |
| 6917 | "Host: www.example.org\r\n" |
| 6918 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6919 | }; |
| 6920 | |
| 6921 | MockRead data_reads[] = { |
| 6922 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6923 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6924 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6926 | }; |
| 6927 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6928 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6930 | |
| 6931 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6932 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6933 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6935 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6938 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6941 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6943 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6946 | ASSERT_TRUE(response); |
| 6947 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6948 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6949 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6950 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6951 | |
| 6952 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6953 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6954 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6955 | EXPECT_EQ("hello world", response_data); |
| 6956 | |
| 6957 | // Empty the current queue. This is necessary because idle sockets are |
| 6958 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6959 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6960 | |
| 6961 | // 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] | 6962 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6963 | } |
| 6964 | |
| 6965 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6966 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6967 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6968 | HttpRequestInfo request; |
| 6969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6970 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6971 | |
| 6972 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6973 | MockWrite( |
| 6974 | "GET / HTTP/1.1\r\n" |
| 6975 | "Host: www.example.org\r\n" |
| 6976 | "Connection: keep-alive\r\n\r\n"), |
| 6977 | MockWrite( |
| 6978 | "GET / HTTP/1.1\r\n" |
| 6979 | "Host: www.example.org\r\n" |
| 6980 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6981 | }; |
| 6982 | |
| 6983 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6984 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6985 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6986 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6987 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6988 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6989 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6991 | |
| 6992 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6993 | data_writes, arraysize(data_writes)); |
| 6994 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6995 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6997 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6999 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7002 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7003 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7005 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7006 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7008 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7009 | |
| 7010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7011 | ASSERT_TRUE(response); |
| 7012 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7013 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7014 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7015 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7016 | |
| 7017 | std::string response_data; |
| 7018 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7019 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7020 | EXPECT_EQ("hello world", response_data); |
| 7021 | |
| 7022 | // Empty the current queue. This is necessary because idle sockets are |
| 7023 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7024 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7025 | |
| 7026 | // 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] | 7027 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7028 | |
| 7029 | // Now start the second transaction, which should reuse the previous socket. |
| 7030 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7031 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7032 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7034 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7035 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7037 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7038 | |
| 7039 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7040 | ASSERT_TRUE(response); |
| 7041 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7042 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7043 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7044 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7045 | |
| 7046 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7047 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7048 | EXPECT_EQ("hello world", response_data); |
| 7049 | |
| 7050 | // Empty the current queue. This is necessary because idle sockets are |
| 7051 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7052 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7053 | |
| 7054 | // 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] | 7055 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7056 | } |
| 7057 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7058 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7059 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7060 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7061 | HttpRequestInfo request; |
| 7062 | request.method = "GET"; |
| 7063 | request.url = GURL("http://www.example.org/"); |
| 7064 | request.load_flags = 0; |
| 7065 | |
| 7066 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7069 | |
| 7070 | MockRead data_reads[] = { |
| 7071 | // A part of the response body is received with the response headers. |
| 7072 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7073 | // The rest of the response body is received in two parts. |
| 7074 | MockRead("lo"), MockRead(" world"), |
| 7075 | MockRead("junk"), // Should not be read!! |
| 7076 | MockRead(SYNCHRONOUS, OK), |
| 7077 | }; |
| 7078 | |
| 7079 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7080 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7081 | |
| 7082 | TestCompletionCallback callback; |
| 7083 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7084 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7086 | |
| 7087 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7089 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7090 | ASSERT_TRUE(response); |
| 7091 | EXPECT_TRUE(response->headers); |
| 7092 | std::string status_line = response->headers->GetStatusLine(); |
| 7093 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7094 | |
| 7095 | // Make memory critical notification and ensure the transaction still has been |
| 7096 | // operating right. |
| 7097 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7098 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7099 | base::RunLoop().RunUntilIdle(); |
| 7100 | |
| 7101 | // Socket should not be flushed as long as it is not idle. |
| 7102 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7103 | |
| 7104 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7105 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7106 | EXPECT_THAT(rv, IsOk()); |
| 7107 | EXPECT_EQ("hello world", response_data); |
| 7108 | |
| 7109 | // Empty the current queue. This is necessary because idle sockets are |
| 7110 | // added to the connection pool asynchronously with a PostTask. |
| 7111 | base::RunLoop().RunUntilIdle(); |
| 7112 | |
| 7113 | // We now check to make sure the socket was added back to the pool. |
| 7114 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7115 | |
| 7116 | // Idle sockets should be flushed now. |
| 7117 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7118 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7119 | base::RunLoop().RunUntilIdle(); |
| 7120 | |
| 7121 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7122 | } |
| 7123 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7124 | // Disable idle socket closing on memory pressure. |
| 7125 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7126 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7127 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7128 | HttpRequestInfo request; |
| 7129 | request.method = "GET"; |
| 7130 | request.url = GURL("http://www.example.org/"); |
| 7131 | request.load_flags = 0; |
| 7132 | |
| 7133 | // Disable idle socket closing on memory pressure. |
| 7134 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7136 | |
| 7137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7138 | |
| 7139 | MockRead data_reads[] = { |
| 7140 | // A part of the response body is received with the response headers. |
| 7141 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7142 | // The rest of the response body is received in two parts. |
| 7143 | MockRead("lo"), MockRead(" world"), |
| 7144 | MockRead("junk"), // Should not be read!! |
| 7145 | MockRead(SYNCHRONOUS, OK), |
| 7146 | }; |
| 7147 | |
| 7148 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7150 | |
| 7151 | TestCompletionCallback callback; |
| 7152 | |
| 7153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7155 | |
| 7156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7157 | |
| 7158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7159 | ASSERT_TRUE(response); |
| 7160 | EXPECT_TRUE(response->headers); |
| 7161 | std::string status_line = response->headers->GetStatusLine(); |
| 7162 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7163 | |
| 7164 | // Make memory critical notification and ensure the transaction still has been |
| 7165 | // operating right. |
| 7166 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7167 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7168 | base::RunLoop().RunUntilIdle(); |
| 7169 | |
| 7170 | // Socket should not be flushed as long as it is not idle. |
| 7171 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7172 | |
| 7173 | std::string response_data; |
| 7174 | rv = ReadTransaction(&trans, &response_data); |
| 7175 | EXPECT_THAT(rv, IsOk()); |
| 7176 | EXPECT_EQ("hello world", response_data); |
| 7177 | |
| 7178 | // Empty the current queue. This is necessary because idle sockets are |
| 7179 | // added to the connection pool asynchronously with a PostTask. |
| 7180 | base::RunLoop().RunUntilIdle(); |
| 7181 | |
| 7182 | // We now check to make sure the socket was added back to the pool. |
| 7183 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7184 | |
| 7185 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7186 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7187 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7188 | base::RunLoop().RunUntilIdle(); |
| 7189 | |
| 7190 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7191 | |
| 7192 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7193 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7194 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7195 | base::RunLoop().RunUntilIdle(); |
| 7196 | |
| 7197 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7198 | } |
| 7199 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7200 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7201 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7202 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7203 | HttpRequestInfo request; |
| 7204 | request.method = "GET"; |
| 7205 | request.url = GURL("https://www.example.org/"); |
| 7206 | request.load_flags = 0; |
| 7207 | |
| 7208 | MockWrite data_writes[] = { |
| 7209 | MockWrite("GET / HTTP/1.1\r\n" |
| 7210 | "Host: www.example.org\r\n" |
| 7211 | "Connection: keep-alive\r\n\r\n"), |
| 7212 | }; |
| 7213 | |
| 7214 | MockRead data_reads[] = { |
| 7215 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7216 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7217 | |
| 7218 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7220 | |
| 7221 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7222 | arraysize(data_writes)); |
| 7223 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7224 | |
| 7225 | TestCompletionCallback callback; |
| 7226 | |
| 7227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7228 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7229 | |
| 7230 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7231 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7232 | |
| 7233 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7235 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7236 | ASSERT_TRUE(response); |
| 7237 | ASSERT_TRUE(response->headers); |
| 7238 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7239 | |
| 7240 | // Make memory critical notification and ensure the transaction still has been |
| 7241 | // operating right. |
| 7242 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7243 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7244 | base::RunLoop().RunUntilIdle(); |
| 7245 | |
| 7246 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7247 | |
| 7248 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7249 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7250 | EXPECT_THAT(rv, IsOk()); |
| 7251 | EXPECT_EQ("hello world", response_data); |
| 7252 | |
| 7253 | // Empty the current queue. This is necessary because idle sockets are |
| 7254 | // added to the connection pool asynchronously with a PostTask. |
| 7255 | base::RunLoop().RunUntilIdle(); |
| 7256 | |
| 7257 | // We now check to make sure the socket was added back to the pool. |
| 7258 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7259 | |
| 7260 | // Make memory notification once again and ensure idle socket is closed. |
| 7261 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7262 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7263 | base::RunLoop().RunUntilIdle(); |
| 7264 | |
| 7265 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7266 | } |
| 7267 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7268 | // Make sure that we recycle a socket after a zero-length response. |
| 7269 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7270 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7271 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7272 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7273 | request.url = GURL( |
| 7274 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7275 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7276 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7277 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7278 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7280 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7281 | MockRead data_reads[] = { |
| 7282 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7283 | "Content-Length: 0\r\n" |
| 7284 | "Content-Type: text/html\r\n\r\n"), |
| 7285 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7286 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7287 | }; |
| 7288 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7289 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7290 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7291 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7292 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7293 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7294 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7296 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7300 | |
| 7301 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7305 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7306 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7307 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7308 | std::string status_line = response->headers->GetStatusLine(); |
| 7309 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7310 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7311 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7312 | |
| 7313 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7314 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7316 | EXPECT_EQ("", response_data); |
| 7317 | |
| 7318 | // Empty the current queue. This is necessary because idle sockets are |
| 7319 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7320 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7321 | |
| 7322 | // 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] | 7323 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7324 | } |
| 7325 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7326 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7327 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7328 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7329 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7330 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7331 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7332 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7333 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7334 | // after use. |
| 7335 | request[0].method = "GET"; |
| 7336 | request[0].url = GURL("http://www.google.com/"); |
| 7337 | request[0].load_flags = 0; |
| 7338 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7339 | // transaction 1. The first attempts fails when writing the POST data. |
| 7340 | // This causes the transaction to retry with a new socket. The second |
| 7341 | // attempt succeeds. |
| 7342 | request[1].method = "POST"; |
| 7343 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7344 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7345 | request[1].load_flags = 0; |
| 7346 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7348 | |
| 7349 | // The first socket is used for transaction 1 and the first attempt of |
| 7350 | // transaction 2. |
| 7351 | |
| 7352 | // The response of transaction 1. |
| 7353 | MockRead data_reads1[] = { |
| 7354 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7355 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7356 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7357 | }; |
| 7358 | // The mock write results of transaction 1 and the first attempt of |
| 7359 | // transaction 2. |
| 7360 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7361 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7362 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7363 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7364 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7365 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7366 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7367 | |
| 7368 | // The second socket is used for the second attempt of transaction 2. |
| 7369 | |
| 7370 | // The response of transaction 2. |
| 7371 | MockRead data_reads2[] = { |
| 7372 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7373 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7374 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7375 | }; |
| 7376 | // The mock write results of the second attempt of transaction 2. |
| 7377 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7378 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7379 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7380 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7381 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7382 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7383 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7384 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7385 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7386 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7387 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7388 | "hello world", "welcome" |
| 7389 | }; |
| 7390 | |
| 7391 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7393 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7394 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7396 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7398 | |
| 7399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7401 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7402 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7403 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7404 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7405 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7406 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7407 | |
| 7408 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7409 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7411 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7412 | } |
| 7413 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7414 | |
| 7415 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7416 | // 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] | 7417 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7418 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7419 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7420 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7421 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7422 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7423 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7425 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7426 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7427 | // The password contains an escaped character -- for this test to pass it |
| 7428 | // will need to be unescaped by HttpNetworkTransaction. |
| 7429 | EXPECT_EQ("b%40r", request.url.password()); |
| 7430 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7431 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7432 | MockWrite( |
| 7433 | "GET / HTTP/1.1\r\n" |
| 7434 | "Host: www.example.org\r\n" |
| 7435 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7436 | }; |
| 7437 | |
| 7438 | MockRead data_reads1[] = { |
| 7439 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7440 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7441 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7442 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7443 | }; |
| 7444 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7445 | // After the challenge above, the transaction will be restarted using the |
| 7446 | // identity from the url (foo, b@r) to answer the challenge. |
| 7447 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7448 | MockWrite( |
| 7449 | "GET / HTTP/1.1\r\n" |
| 7450 | "Host: www.example.org\r\n" |
| 7451 | "Connection: keep-alive\r\n" |
| 7452 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7453 | }; |
| 7454 | |
| 7455 | MockRead data_reads2[] = { |
| 7456 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7457 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7458 | MockRead(SYNCHRONOUS, OK), |
| 7459 | }; |
| 7460 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7461 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7462 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7463 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7464 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7465 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7468 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7469 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7471 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7472 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7473 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7474 | |
| 7475 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7476 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7478 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7479 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7482 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7483 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7484 | |
| 7485 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7486 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7487 | |
| 7488 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7489 | |
| 7490 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7491 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7492 | } |
| 7493 | |
| 7494 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7495 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7496 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7497 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7498 | HttpRequestInfo request; |
| 7499 | request.method = "GET"; |
| 7500 | // Note: the URL has a username:password in it. The password "baz" is |
| 7501 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7502 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7503 | |
| 7504 | request.load_flags = LOAD_NORMAL; |
| 7505 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7508 | |
| 7509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7510 | MockWrite( |
| 7511 | "GET / HTTP/1.1\r\n" |
| 7512 | "Host: www.example.org\r\n" |
| 7513 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7514 | }; |
| 7515 | |
| 7516 | MockRead data_reads1[] = { |
| 7517 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7518 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7519 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7520 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7521 | }; |
| 7522 | |
| 7523 | // After the challenge above, the transaction will be restarted using the |
| 7524 | // identity from the url (foo, baz) to answer the challenge. |
| 7525 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7526 | MockWrite( |
| 7527 | "GET / HTTP/1.1\r\n" |
| 7528 | "Host: www.example.org\r\n" |
| 7529 | "Connection: keep-alive\r\n" |
| 7530 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7531 | }; |
| 7532 | |
| 7533 | MockRead data_reads2[] = { |
| 7534 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7535 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7536 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7537 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7538 | }; |
| 7539 | |
| 7540 | // After the challenge above, the transaction will be restarted using the |
| 7541 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7542 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7543 | MockWrite( |
| 7544 | "GET / HTTP/1.1\r\n" |
| 7545 | "Host: www.example.org\r\n" |
| 7546 | "Connection: keep-alive\r\n" |
| 7547 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7548 | }; |
| 7549 | |
| 7550 | MockRead data_reads3[] = { |
| 7551 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7552 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7553 | MockRead(SYNCHRONOUS, OK), |
| 7554 | }; |
| 7555 | |
| 7556 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7557 | data_writes1, arraysize(data_writes1)); |
| 7558 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7559 | data_writes2, arraysize(data_writes2)); |
| 7560 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7561 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7562 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7564 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7565 | |
| 7566 | TestCompletionCallback callback1; |
| 7567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7568 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7569 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7570 | |
| 7571 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7572 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7573 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7574 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7575 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7576 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7578 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7579 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7580 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7583 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7584 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7585 | |
| 7586 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7587 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7588 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7589 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7590 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7591 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7592 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7593 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7594 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7595 | |
| 7596 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7597 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7598 | |
| 7599 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7600 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7601 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7602 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7603 | } |
| 7604 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7605 | |
| 7606 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7607 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7608 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7609 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7610 | HttpRequestInfo request; |
| 7611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7612 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7613 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7614 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7615 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7616 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7617 | |
| 7618 | MockWrite data_writes1[] = { |
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\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7623 | }; |
| 7624 | |
| 7625 | MockRead data_reads1[] = { |
| 7626 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7627 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7628 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7629 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7630 | }; |
| 7631 | |
| 7632 | // After the challenge above, the transaction will be restarted using the |
| 7633 | // identity supplied by the user, not the one in the URL, to answer the |
| 7634 | // challenge. |
| 7635 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7636 | MockWrite( |
| 7637 | "GET / HTTP/1.1\r\n" |
| 7638 | "Host: www.example.org\r\n" |
| 7639 | "Connection: keep-alive\r\n" |
| 7640 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7641 | }; |
| 7642 | |
| 7643 | MockRead data_reads3[] = { |
| 7644 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7645 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7646 | MockRead(SYNCHRONOUS, OK), |
| 7647 | }; |
| 7648 | |
| 7649 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7650 | data_writes1, arraysize(data_writes1)); |
| 7651 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7652 | data_writes3, arraysize(data_writes3)); |
| 7653 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7654 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7655 | |
| 7656 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7657 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7658 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7659 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7660 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7661 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7663 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7664 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7665 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7666 | |
| 7667 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7668 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7670 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7671 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7672 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7674 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7675 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7676 | |
| 7677 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7678 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7679 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7680 | |
| 7681 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7682 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7683 | } |
| 7684 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7685 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7686 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7688 | |
| 7689 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7690 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7691 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7693 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7696 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7697 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7698 | MockWrite( |
| 7699 | "GET /x/y/z HTTP/1.1\r\n" |
| 7700 | "Host: www.example.org\r\n" |
| 7701 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7702 | }; |
| 7703 | |
| 7704 | MockRead data_reads1[] = { |
| 7705 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7706 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7707 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7708 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7709 | }; |
| 7710 | |
| 7711 | // Resend with authorization (username=foo, password=bar) |
| 7712 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7713 | MockWrite( |
| 7714 | "GET /x/y/z HTTP/1.1\r\n" |
| 7715 | "Host: www.example.org\r\n" |
| 7716 | "Connection: keep-alive\r\n" |
| 7717 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7718 | }; |
| 7719 | |
| 7720 | // Sever accepts the authorization. |
| 7721 | MockRead data_reads2[] = { |
| 7722 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7723 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7725 | }; |
| 7726 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7727 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7728 | data_writes1, arraysize(data_writes1)); |
| 7729 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7730 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7731 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7732 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7734 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7736 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7738 | |
| 7739 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7740 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7743 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7744 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7746 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7748 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7749 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7751 | |
| 7752 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7755 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7756 | ASSERT_TRUE(response); |
| 7757 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7758 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7759 | } |
| 7760 | |
| 7761 | // ------------------------------------------------------------------------ |
| 7762 | |
| 7763 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7764 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7765 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7766 | request.method = "GET"; |
| 7767 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7768 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7769 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7772 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7773 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7774 | MockWrite( |
| 7775 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7776 | "Host: www.example.org\r\n" |
| 7777 | "Connection: keep-alive\r\n" |
| 7778 | // Send preemptive authorization for MyRealm1 |
| 7779 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7780 | }; |
| 7781 | |
| 7782 | // The server didn't like the preemptive authorization, and |
| 7783 | // challenges us for a different realm (MyRealm2). |
| 7784 | MockRead data_reads1[] = { |
| 7785 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7786 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7787 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7788 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7789 | }; |
| 7790 | |
| 7791 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7792 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7793 | MockWrite( |
| 7794 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7795 | "Host: www.example.org\r\n" |
| 7796 | "Connection: keep-alive\r\n" |
| 7797 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7798 | }; |
| 7799 | |
| 7800 | // Sever accepts the authorization. |
| 7801 | MockRead data_reads2[] = { |
| 7802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7803 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7805 | }; |
| 7806 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7807 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7808 | data_writes1, arraysize(data_writes1)); |
| 7809 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7810 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7811 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7812 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7814 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7816 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7818 | |
| 7819 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7820 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7822 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7823 | ASSERT_TRUE(response); |
| 7824 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7825 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7826 | EXPECT_EQ("http://www.example.org", |
| 7827 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7828 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7829 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7831 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7833 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7834 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7836 | |
| 7837 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7840 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7841 | ASSERT_TRUE(response); |
| 7842 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7843 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7844 | } |
| 7845 | |
| 7846 | // ------------------------------------------------------------------------ |
| 7847 | |
| 7848 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7849 | // succeed with preemptive authorization. |
| 7850 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7851 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7853 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7854 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7856 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7857 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7858 | MockWrite( |
| 7859 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7860 | "Host: www.example.org\r\n" |
| 7861 | "Connection: keep-alive\r\n" |
| 7862 | // The authorization for MyRealm1 gets sent preemptively |
| 7863 | // (since the url is in the same protection space) |
| 7864 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7865 | }; |
| 7866 | |
| 7867 | // Sever accepts the preemptive authorization |
| 7868 | MockRead data_reads1[] = { |
| 7869 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7870 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7871 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7872 | }; |
| 7873 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7874 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7875 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7877 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7878 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7880 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7882 | |
| 7883 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7886 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7887 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7888 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7889 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7890 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7891 | } |
| 7892 | |
| 7893 | // ------------------------------------------------------------------------ |
| 7894 | |
| 7895 | // Transaction 4: request another URL in MyRealm (however the |
| 7896 | // url is not known to belong to the protection space, so no pre-auth). |
| 7897 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7898 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7900 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7902 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7903 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7904 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7905 | MockWrite( |
| 7906 | "GET /x/1 HTTP/1.1\r\n" |
| 7907 | "Host: www.example.org\r\n" |
| 7908 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7909 | }; |
| 7910 | |
| 7911 | MockRead data_reads1[] = { |
| 7912 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7913 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7914 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7915 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7916 | }; |
| 7917 | |
| 7918 | // Resend with authorization from MyRealm's cache. |
| 7919 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7920 | MockWrite( |
| 7921 | "GET /x/1 HTTP/1.1\r\n" |
| 7922 | "Host: www.example.org\r\n" |
| 7923 | "Connection: keep-alive\r\n" |
| 7924 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7925 | }; |
| 7926 | |
| 7927 | // Sever accepts the authorization. |
| 7928 | MockRead data_reads2[] = { |
| 7929 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7930 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7932 | }; |
| 7933 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7934 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7935 | data_writes1, arraysize(data_writes1)); |
| 7936 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7937 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7938 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7939 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7941 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7943 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7945 | |
| 7946 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7947 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7949 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7950 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7951 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7952 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7953 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7954 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7955 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7957 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7958 | ASSERT_TRUE(response); |
| 7959 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7960 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7961 | } |
| 7962 | |
| 7963 | // ------------------------------------------------------------------------ |
| 7964 | |
| 7965 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7966 | // cached identity. Should invalidate and re-prompt. |
| 7967 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7968 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7970 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7971 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7973 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7974 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7975 | MockWrite( |
| 7976 | "GET /p/q/t HTTP/1.1\r\n" |
| 7977 | "Host: www.example.org\r\n" |
| 7978 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7979 | }; |
| 7980 | |
| 7981 | MockRead data_reads1[] = { |
| 7982 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7983 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7984 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7985 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7986 | }; |
| 7987 | |
| 7988 | // Resend with authorization from cache for MyRealm. |
| 7989 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7990 | MockWrite( |
| 7991 | "GET /p/q/t HTTP/1.1\r\n" |
| 7992 | "Host: www.example.org\r\n" |
| 7993 | "Connection: keep-alive\r\n" |
| 7994 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7995 | }; |
| 7996 | |
| 7997 | // Sever rejects the authorization. |
| 7998 | MockRead data_reads2[] = { |
| 7999 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8000 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8001 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8002 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8003 | }; |
| 8004 | |
| 8005 | // At this point we should prompt for new credentials for MyRealm. |
| 8006 | // Restart with username=foo3, password=foo4. |
| 8007 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8008 | MockWrite( |
| 8009 | "GET /p/q/t HTTP/1.1\r\n" |
| 8010 | "Host: www.example.org\r\n" |
| 8011 | "Connection: keep-alive\r\n" |
| 8012 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8013 | }; |
| 8014 | |
| 8015 | // Sever accepts the authorization. |
| 8016 | MockRead data_reads3[] = { |
| 8017 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8018 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8020 | }; |
| 8021 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8022 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8023 | data_writes1, arraysize(data_writes1)); |
| 8024 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8025 | data_writes2, arraysize(data_writes2)); |
| 8026 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8027 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8028 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8029 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8030 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8031 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8032 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8034 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8036 | |
| 8037 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8038 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8040 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8041 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8042 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8044 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8045 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8046 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8049 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8050 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8052 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8054 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8055 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8057 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8058 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8061 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8062 | ASSERT_TRUE(response); |
| 8063 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8064 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8065 | } |
| 8066 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8067 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8068 | // Tests that nonce count increments when multiple auth attempts |
| 8069 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8070 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8071 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8072 | new HttpAuthHandlerDigest::Factory(); |
| 8073 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8074 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8075 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8076 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8077 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8078 | |
| 8079 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8080 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8081 | HttpRequestInfo request; |
| 8082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8083 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [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] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8087 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8088 | MockWrite( |
| 8089 | "GET /x/y/z HTTP/1.1\r\n" |
| 8090 | "Host: www.example.org\r\n" |
| 8091 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8092 | }; |
| 8093 | |
| 8094 | MockRead data_reads1[] = { |
| 8095 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8096 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8097 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8098 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8099 | }; |
| 8100 | |
| 8101 | // Resend with authorization (username=foo, password=bar) |
| 8102 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8103 | MockWrite( |
| 8104 | "GET /x/y/z HTTP/1.1\r\n" |
| 8105 | "Host: www.example.org\r\n" |
| 8106 | "Connection: keep-alive\r\n" |
| 8107 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8108 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8109 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8110 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8111 | }; |
| 8112 | |
| 8113 | // Sever accepts the authorization. |
| 8114 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8115 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8116 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8117 | }; |
| 8118 | |
| 8119 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8120 | data_writes1, arraysize(data_writes1)); |
| 8121 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8122 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8124 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8125 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8126 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8127 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8128 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8130 | |
| 8131 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8134 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8135 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8136 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8137 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8138 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8140 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8141 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8143 | |
| 8144 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8147 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8148 | ASSERT_TRUE(response); |
| 8149 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8150 | } |
| 8151 | |
| 8152 | // ------------------------------------------------------------------------ |
| 8153 | |
| 8154 | // Transaction 2: Request another resource in digestive's protection space. |
| 8155 | // This will preemptively add an Authorization header which should have an |
| 8156 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8157 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8158 | HttpRequestInfo request; |
| 8159 | request.method = "GET"; |
| 8160 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8161 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8162 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8165 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8166 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8167 | MockWrite( |
| 8168 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8169 | "Host: www.example.org\r\n" |
| 8170 | "Connection: keep-alive\r\n" |
| 8171 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8172 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8173 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8174 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8175 | }; |
| 8176 | |
| 8177 | // Sever accepts the authorization. |
| 8178 | MockRead data_reads1[] = { |
| 8179 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8180 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8182 | }; |
| 8183 | |
| 8184 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8185 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8186 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8188 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8189 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8190 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8191 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8192 | |
| 8193 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8194 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8196 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8197 | ASSERT_TRUE(response); |
| 8198 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8199 | } |
| 8200 | } |
| 8201 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8202 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8203 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8204 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8206 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8207 | |
| 8208 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8209 | trans.read_buf_ = new IOBuffer(15); |
| 8210 | trans.read_buf_len_ = 15; |
| 8211 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8212 | |
| 8213 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8214 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8215 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8216 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8217 | response->response_time = base::Time::Now(); |
| 8218 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8219 | |
| 8220 | { // Setup state for response_.vary_data |
| 8221 | HttpRequestInfo request; |
| 8222 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8223 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8224 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8225 | request.extra_headers.SetHeader("Foo", "1"); |
| 8226 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8227 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8228 | } |
| 8229 | |
| 8230 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8231 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8232 | |
| 8233 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8234 | EXPECT_FALSE(trans.read_buf_); |
| 8235 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8236 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8237 | EXPECT_FALSE(response->auth_challenge); |
| 8238 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8239 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8240 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8241 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8242 | } |
| 8243 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8244 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8245 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8246 | HttpRequestInfo request; |
| 8247 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8248 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8249 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8252 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8253 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8254 | MockWrite( |
| 8255 | "GET / HTTP/1.1\r\n" |
| 8256 | "Host: www.example.org\r\n" |
| 8257 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8258 | }; |
| 8259 | |
| 8260 | MockRead data_reads[] = { |
| 8261 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8262 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8263 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8265 | }; |
| 8266 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8267 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8268 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8269 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8270 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8271 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8272 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8273 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8274 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8278 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8280 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8282 | |
| 8283 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8284 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8286 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8288 | |
| 8289 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8290 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8292 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8293 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8294 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8295 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8296 | } |
| 8297 | |
| 8298 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8299 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8300 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8301 | session_deps_.proxy_resolution_service = |
| 8302 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8303 | |
| 8304 | HttpRequestInfo request; |
| 8305 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8306 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8307 | |
| 8308 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8309 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8310 | "Host: www.example.org:443\r\n" |
| 8311 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8312 | }; |
| 8313 | |
| 8314 | MockRead proxy_reads[] = { |
| 8315 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8316 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8317 | }; |
| 8318 | |
| 8319 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8320 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8321 | "Host: www.example.org:443\r\n" |
| 8322 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8323 | MockWrite("GET / HTTP/1.1\r\n" |
| 8324 | "Host: www.example.org\r\n" |
| 8325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8326 | }; |
| 8327 | |
| 8328 | MockRead data_reads[] = { |
| 8329 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8330 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8331 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8332 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8333 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8334 | }; |
| 8335 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8336 | StaticSocketDataProvider ssl_bad_certificate( |
| 8337 | proxy_reads, arraysize(proxy_reads), |
| 8338 | proxy_writes, arraysize(proxy_writes)); |
| 8339 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8340 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8341 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8342 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8343 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8344 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8345 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8347 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8349 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8350 | |
| 8351 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8352 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8355 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8357 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8359 | |
| 8360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8361 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8363 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8365 | |
| 8366 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8369 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8370 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8371 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8372 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8373 | } |
| 8374 | } |
| 8375 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8376 | |
| 8377 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8378 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8379 | session_deps_.proxy_resolution_service = |
| 8380 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8381 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8382 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8383 | |
| 8384 | HttpRequestInfo request; |
| 8385 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8386 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8387 | |
| 8388 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8389 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8390 | "Host: www.example.org:443\r\n" |
| 8391 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8392 | MockWrite("GET / HTTP/1.1\r\n" |
| 8393 | "Host: www.example.org\r\n" |
| 8394 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8395 | }; |
| 8396 | |
| 8397 | MockRead data_reads[] = { |
| 8398 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8399 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8400 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8401 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8402 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8403 | }; |
| 8404 | |
| 8405 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8406 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8407 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8408 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8409 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8410 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8411 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8413 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8414 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8415 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8416 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8417 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8419 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8421 | |
| 8422 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8423 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8424 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8425 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8426 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8427 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8428 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8429 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8430 | EXPECT_EQ(200, response->headers->response_code()); |
| 8431 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8432 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8433 | |
| 8434 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8435 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8436 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8437 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8438 | } |
| 8439 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8440 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8441 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8442 | session_deps_.proxy_resolution_service = |
| 8443 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8444 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8445 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8446 | |
| 8447 | HttpRequestInfo request; |
| 8448 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8449 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8450 | |
| 8451 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8452 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8453 | "Host: www.example.org:443\r\n" |
| 8454 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8455 | }; |
| 8456 | |
| 8457 | MockRead data_reads[] = { |
| 8458 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8459 | MockRead("Location: http://login.example.com/\r\n"), |
| 8460 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8461 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8462 | }; |
| 8463 | |
| 8464 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8465 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8466 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8467 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8468 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8471 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8472 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8475 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8476 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8478 | |
| 8479 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8480 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8481 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8482 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8483 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8484 | |
| 8485 | EXPECT_EQ(302, response->headers->response_code()); |
| 8486 | std::string url; |
| 8487 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8488 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8489 | |
| 8490 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8491 | // timing for the proxy connection instead of the connection to the host, |
| 8492 | // and no send / receive times. |
| 8493 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8494 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8495 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8496 | |
| 8497 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8498 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8499 | |
| 8500 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8501 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8502 | load_timing_info.proxy_resolve_end); |
| 8503 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8504 | load_timing_info.connect_timing.connect_start); |
| 8505 | ExpectConnectTimingHasTimes( |
| 8506 | load_timing_info.connect_timing, |
| 8507 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8508 | |
| 8509 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8510 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8511 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8512 | } |
| 8513 | |
| 8514 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8515 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8516 | session_deps_.proxy_resolution_service = |
| 8517 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8518 | |
| 8519 | HttpRequestInfo request; |
| 8520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8521 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8522 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8523 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8524 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8525 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8526 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8527 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8528 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8529 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8530 | }; |
| 8531 | |
| 8532 | static const char* const kExtraHeaders[] = { |
| 8533 | "location", |
| 8534 | "http://login.example.com/", |
| 8535 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8536 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8537 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8538 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8539 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8540 | }; |
| 8541 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8542 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8543 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8544 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8545 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8546 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8548 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8549 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8550 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8557 | |
| 8558 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8559 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8560 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8561 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8562 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8563 | |
| 8564 | EXPECT_EQ(302, response->headers->response_code()); |
| 8565 | std::string url; |
| 8566 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8567 | EXPECT_EQ("http://login.example.com/", url); |
| 8568 | } |
| 8569 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8570 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8571 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8572 | session_deps_.proxy_resolution_service = |
| 8573 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8574 | |
| 8575 | HttpRequestInfo request; |
| 8576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8577 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8578 | |
| 8579 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8580 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8581 | "Host: www.example.org:443\r\n" |
| 8582 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8583 | }; |
| 8584 | |
| 8585 | MockRead data_reads[] = { |
| 8586 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8587 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8588 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8589 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8590 | }; |
| 8591 | |
| 8592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8593 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8594 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8595 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8597 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8599 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8606 | |
| 8607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8608 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8609 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8610 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8611 | } |
| 8612 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8613 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8614 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8615 | session_deps_.proxy_resolution_service = |
| 8616 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8617 | |
| 8618 | HttpRequestInfo request; |
| 8619 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8620 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8621 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8622 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8623 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8624 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8625 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8626 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8627 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8628 | }; |
| 8629 | |
| 8630 | static const char* const kExtraHeaders[] = { |
| 8631 | "location", |
| 8632 | "http://login.example.com/", |
| 8633 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8634 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8635 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8636 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8637 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8638 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8639 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8640 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8641 | }; |
| 8642 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8643 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8644 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8645 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8646 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8647 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8648 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8651 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8652 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8654 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8656 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8658 | |
| 8659 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8660 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8661 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8662 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8663 | } |
| 8664 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8665 | // Test the request-challenge-retry sequence for basic auth, through |
| 8666 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8667 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8668 | HttpRequestInfo request; |
| 8669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8670 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8671 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8672 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8673 | |
| 8674 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8675 | session_deps_.proxy_resolution_service = |
| 8676 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8677 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8678 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8680 | |
| 8681 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8682 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8683 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8684 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8685 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8686 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8688 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8689 | // be issuing -- the final header line contains the credentials. |
| 8690 | const char* const kAuthCredentials[] = { |
| 8691 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8692 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8693 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8694 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8695 | HostPortPair("www.example.org", 443))); |
| 8696 | // fetch https://www.example.org/ via HTTP |
| 8697 | const char get[] = |
| 8698 | "GET / HTTP/1.1\r\n" |
| 8699 | "Host: www.example.org\r\n" |
| 8700 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8701 | SpdySerializedFrame wrapped_get( |
| 8702 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8703 | |
| 8704 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8705 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8706 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8707 | }; |
| 8708 | |
| 8709 | // The proxy responds to the connect with a 407, using a persistent |
| 8710 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8711 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8712 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8713 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8714 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8715 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8716 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8717 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8718 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8719 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8720 | "Content-Length: 5\r\n\r\n"; |
| 8721 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8722 | SpdySerializedFrame wrapped_get_resp( |
| 8723 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8724 | SpdySerializedFrame wrapped_body( |
| 8725 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8726 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8727 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8728 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8729 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8730 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8731 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8732 | }; |
| 8733 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8734 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8735 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8736 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8737 | // Negotiate SPDY to the proxy |
| 8738 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8739 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8741 | // Vanilla SSL to the server |
| 8742 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8744 | |
| 8745 | TestCompletionCallback callback1; |
| 8746 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8747 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8748 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8749 | |
| 8750 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8751 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8752 | |
| 8753 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8754 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8755 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8756 | log.GetEntries(&entries); |
| 8757 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8758 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8759 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8760 | ExpectLogContainsSomewhere( |
| 8761 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8762 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8763 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8764 | |
| 8765 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8766 | ASSERT_TRUE(response); |
| 8767 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8768 | EXPECT_EQ(407, response->headers->response_code()); |
| 8769 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8770 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8771 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8772 | |
| 8773 | TestCompletionCallback callback2; |
| 8774 | |
| 8775 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8776 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8778 | |
| 8779 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8780 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8781 | |
| 8782 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8783 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8784 | |
| 8785 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8786 | EXPECT_EQ(200, response->headers->response_code()); |
| 8787 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8788 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8789 | |
| 8790 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8791 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8792 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8793 | LoadTimingInfo load_timing_info; |
| 8794 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8795 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8796 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8797 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8798 | trans.reset(); |
| 8799 | session->CloseAllConnections(); |
| 8800 | } |
| 8801 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8802 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8803 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8804 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8805 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8806 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8807 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8808 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8809 | HttpRequestInfo request; |
| 8810 | HttpRequestInfo push_request; |
| 8811 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8812 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8813 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8814 | push_request.method = "GET"; |
| 8815 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8816 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8817 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8818 | session_deps_.proxy_resolution_service = |
| 8819 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8820 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8821 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8822 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8823 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8824 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8826 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8827 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8828 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8829 | SpdySerializedFrame stream2_priority( |
| 8830 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8831 | |
| 8832 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8833 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8834 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8835 | }; |
| 8836 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8837 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 8838 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 8839 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8840 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8841 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8842 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8843 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8844 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8845 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8846 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8847 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8848 | |
| 8849 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8850 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 8851 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8852 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8853 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8854 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8855 | }; |
| 8856 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8857 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8858 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8859 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8860 | // Negotiate SPDY to the proxy |
| 8861 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8862 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8864 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8865 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8866 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8867 | TestCompletionCallback callback; |
| 8868 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8870 | |
| 8871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8872 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8873 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8874 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8875 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8876 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8877 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8879 | |
| 8880 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8881 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8882 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8883 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8884 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8885 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8886 | |
| 8887 | EXPECT_EQ(200, response->headers->response_code()); |
| 8888 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8889 | |
| 8890 | std::string response_data; |
| 8891 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8892 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8893 | EXPECT_EQ("hello!", response_data); |
| 8894 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8895 | LoadTimingInfo load_timing_info; |
| 8896 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8897 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8898 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8899 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8900 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8901 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8902 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8903 | |
| 8904 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8905 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8906 | EXPECT_EQ("pushed", response_data); |
| 8907 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8908 | LoadTimingInfo push_load_timing_info; |
| 8909 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8910 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8911 | // The transactions should share a socket ID, despite being for different |
| 8912 | // origins. |
| 8913 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8914 | push_load_timing_info.socket_log_id); |
| 8915 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8916 | trans.reset(); |
| 8917 | push_trans.reset(); |
| 8918 | session->CloseAllConnections(); |
| 8919 | } |
| 8920 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8921 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8922 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8923 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8924 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8925 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8926 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8927 | HttpRequestInfo request; |
| 8928 | |
| 8929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8930 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8931 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8932 | session_deps_.proxy_resolution_service = |
| 8933 | ProxyResolutionService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8934 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8935 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8936 | |
| 8937 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8938 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8939 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8940 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8941 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8942 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8943 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8944 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8945 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8946 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8947 | |
| 8948 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8949 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8950 | }; |
| 8951 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8952 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8953 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8954 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8955 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8956 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8957 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8958 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8959 | |
| 8960 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8961 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8962 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8963 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8964 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8965 | }; |
| 8966 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8967 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8968 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8969 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8970 | // Negotiate SPDY to the proxy |
| 8971 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8972 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8973 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8974 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8975 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8976 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8977 | TestCompletionCallback callback; |
| 8978 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8980 | |
| 8981 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8982 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8983 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8984 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8985 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8986 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8987 | |
| 8988 | EXPECT_EQ(200, response->headers->response_code()); |
| 8989 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8990 | |
| 8991 | std::string response_data; |
| 8992 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8994 | EXPECT_EQ("hello!", response_data); |
| 8995 | |
| 8996 | trans.reset(); |
| 8997 | session->CloseAllConnections(); |
| 8998 | } |
| 8999 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9000 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9001 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9002 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9003 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9004 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9005 | proxy_delegate->set_trusted_spdy_proxy( |
| 9006 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9007 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9008 | HttpRequestInfo request; |
| 9009 | |
| 9010 | request.method = "GET"; |
| 9011 | request.url = GURL("http://www.example.org/"); |
| 9012 | |
| 9013 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9014 | session_deps_.proxy_resolution_service = |
| 9015 | ProxyResolutionService::CreateFixed("https://myproxy:70"); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9016 | BoundTestNetLog log; |
| 9017 | session_deps_.net_log = log.bound().net_log(); |
| 9018 | |
| 9019 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 9020 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9023 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9024 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9025 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9026 | SpdySerializedFrame stream2_priority( |
| 9027 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9028 | |
| 9029 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9030 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9031 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9032 | }; |
| 9033 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9034 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9035 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9036 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9037 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9038 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9039 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9040 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9041 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9042 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9043 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9044 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9045 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9046 | |
| 9047 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9048 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9049 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9050 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9051 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9052 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9053 | }; |
| 9054 | |
| 9055 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9056 | arraysize(spdy_writes)); |
| 9057 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9058 | // Negotiate SPDY to the proxy |
| 9059 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9060 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9062 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9063 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9064 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9065 | TestCompletionCallback callback; |
| 9066 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9068 | |
| 9069 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9070 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9071 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9072 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9073 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9074 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9075 | |
| 9076 | EXPECT_EQ(200, response->headers->response_code()); |
| 9077 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9078 | |
| 9079 | std::string response_data; |
| 9080 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9081 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9082 | EXPECT_EQ("hello!", response_data); |
| 9083 | |
| 9084 | trans.reset(); |
| 9085 | session->CloseAllConnections(); |
| 9086 | } |
| 9087 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9088 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9089 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9090 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9091 | session_deps_.proxy_resolution_service = |
| 9092 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9093 | |
| 9094 | HttpRequestInfo request; |
| 9095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9096 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9097 | |
| 9098 | // Attempt to fetch the URL from a server with a bad cert |
| 9099 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9100 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9101 | "Host: www.example.org:443\r\n" |
| 9102 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9103 | }; |
| 9104 | |
| 9105 | MockRead bad_cert_reads[] = { |
| 9106 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9107 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9108 | }; |
| 9109 | |
| 9110 | // Attempt to fetch the URL with a good cert |
| 9111 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9112 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9113 | "Host: www.example.org:443\r\n" |
| 9114 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9115 | MockWrite("GET / HTTP/1.1\r\n" |
| 9116 | "Host: www.example.org\r\n" |
| 9117 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9118 | }; |
| 9119 | |
| 9120 | MockRead good_cert_reads[] = { |
| 9121 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9122 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9123 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9124 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9125 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9126 | }; |
| 9127 | |
| 9128 | StaticSocketDataProvider ssl_bad_certificate( |
| 9129 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9130 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9131 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9132 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9133 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9134 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9135 | |
| 9136 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9138 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9139 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9140 | |
| 9141 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9142 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9144 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9145 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9146 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9147 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9149 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9150 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9151 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9153 | |
| 9154 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9155 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9157 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9159 | |
| 9160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9164 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9165 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9166 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9167 | } |
| 9168 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9169 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9170 | HttpRequestInfo request; |
| 9171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9172 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9173 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9174 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9178 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9179 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9180 | MockWrite( |
| 9181 | "GET / HTTP/1.1\r\n" |
| 9182 | "Host: www.example.org\r\n" |
| 9183 | "Connection: keep-alive\r\n" |
| 9184 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9185 | }; |
| 9186 | |
| 9187 | // Lastly, the server responds with the actual content. |
| 9188 | MockRead data_reads[] = { |
| 9189 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9190 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9191 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9192 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9193 | }; |
| 9194 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9195 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9196 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9197 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9199 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9200 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9201 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9203 | |
| 9204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9206 | } |
| 9207 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9208 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9209 | HttpRequestInfo request; |
| 9210 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9211 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9212 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9213 | "Chromium Ultra Awesome X Edition"); |
| 9214 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9215 | session_deps_.proxy_resolution_service = |
| 9216 | ProxyResolutionService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9218 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9219 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9220 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9221 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9222 | "Host: www.example.org:443\r\n" |
| 9223 | "Proxy-Connection: keep-alive\r\n" |
| 9224 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9225 | }; |
| 9226 | MockRead data_reads[] = { |
| 9227 | // Return an error, so the transaction stops here (this test isn't |
| 9228 | // interested in the rest). |
| 9229 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9230 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9231 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9232 | }; |
| 9233 | |
| 9234 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9235 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9236 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9237 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9238 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9239 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9240 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9242 | |
| 9243 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9244 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9245 | } |
| 9246 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9247 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9248 | HttpRequestInfo request; |
| 9249 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9250 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9251 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9252 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9253 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9256 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9257 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9258 | MockWrite( |
| 9259 | "GET / HTTP/1.1\r\n" |
| 9260 | "Host: www.example.org\r\n" |
| 9261 | "Connection: keep-alive\r\n" |
| 9262 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9263 | }; |
| 9264 | |
| 9265 | // Lastly, the server responds with the actual content. |
| 9266 | MockRead data_reads[] = { |
| 9267 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9268 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9269 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9270 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9271 | }; |
| 9272 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9273 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9274 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9275 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9276 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9277 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9278 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9279 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9281 | |
| 9282 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9284 | } |
| 9285 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9286 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9287 | HttpRequestInfo request; |
| 9288 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9289 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9290 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9292 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9293 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9294 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9295 | MockWrite( |
| 9296 | "POST / HTTP/1.1\r\n" |
| 9297 | "Host: www.example.org\r\n" |
| 9298 | "Connection: keep-alive\r\n" |
| 9299 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9300 | }; |
| 9301 | |
| 9302 | // Lastly, the server responds with the actual content. |
| 9303 | MockRead data_reads[] = { |
| 9304 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9305 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9306 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9307 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9308 | }; |
| 9309 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9310 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9311 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9312 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9314 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9315 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9316 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9318 | |
| 9319 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9320 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9321 | } |
| 9322 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9323 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9324 | HttpRequestInfo request; |
| 9325 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9326 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9327 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9328 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9329 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9330 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9331 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | MockWrite( |
| 9333 | "PUT / HTTP/1.1\r\n" |
| 9334 | "Host: www.example.org\r\n" |
| 9335 | "Connection: keep-alive\r\n" |
| 9336 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9337 | }; |
| 9338 | |
| 9339 | // Lastly, the server responds with the actual content. |
| 9340 | MockRead data_reads[] = { |
| 9341 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9342 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9343 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9344 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9345 | }; |
| 9346 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9347 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9348 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9349 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9350 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9351 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9355 | |
| 9356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9358 | } |
| 9359 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9360 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9361 | HttpRequestInfo request; |
| 9362 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9363 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9364 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9365 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9366 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9367 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9368 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9369 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9370 | "Host: www.example.org\r\n" |
| 9371 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9372 | }; |
| 9373 | |
| 9374 | // Lastly, the server responds with the actual content. |
| 9375 | MockRead data_reads[] = { |
| 9376 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9377 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9378 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9379 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9380 | }; |
| 9381 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9382 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9383 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9384 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9386 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9388 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9390 | |
| 9391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9393 | } |
| 9394 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9395 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9396 | HttpRequestInfo request; |
| 9397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9398 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9399 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9403 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9404 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9405 | MockWrite( |
| 9406 | "GET / HTTP/1.1\r\n" |
| 9407 | "Host: www.example.org\r\n" |
| 9408 | "Connection: keep-alive\r\n" |
| 9409 | "Pragma: no-cache\r\n" |
| 9410 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9411 | }; |
| 9412 | |
| 9413 | // Lastly, the server responds with the actual content. |
| 9414 | MockRead data_reads[] = { |
| 9415 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9416 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9417 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9418 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9419 | }; |
| 9420 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9421 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9422 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9423 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9425 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9426 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9427 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9428 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9429 | |
| 9430 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9431 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9432 | } |
| 9433 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9434 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9435 | HttpRequestInfo request; |
| 9436 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9437 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9438 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9442 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9443 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9444 | MockWrite( |
| 9445 | "GET / HTTP/1.1\r\n" |
| 9446 | "Host: www.example.org\r\n" |
| 9447 | "Connection: keep-alive\r\n" |
| 9448 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9449 | }; |
| 9450 | |
| 9451 | // Lastly, the server responds with the actual content. |
| 9452 | MockRead data_reads[] = { |
| 9453 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9454 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9455 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9457 | }; |
| 9458 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9460 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9463 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9464 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9465 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9467 | |
| 9468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9470 | } |
| 9471 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9472 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9473 | HttpRequestInfo request; |
| 9474 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9475 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9476 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9477 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9480 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9481 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9482 | MockWrite( |
| 9483 | "GET / HTTP/1.1\r\n" |
| 9484 | "Host: www.example.org\r\n" |
| 9485 | "Connection: keep-alive\r\n" |
| 9486 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9487 | }; |
| 9488 | |
| 9489 | // Lastly, the server responds with the actual content. |
| 9490 | MockRead data_reads[] = { |
| 9491 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9492 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9493 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9494 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9495 | }; |
| 9496 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9497 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9498 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9499 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9501 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9502 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9503 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9505 | |
| 9506 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9507 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9508 | } |
| 9509 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9510 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9511 | HttpRequestInfo request; |
| 9512 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9513 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9514 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9515 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9516 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9517 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9518 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9520 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9521 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9522 | MockWrite( |
| 9523 | "GET / HTTP/1.1\r\n" |
| 9524 | "Host: www.example.org\r\n" |
| 9525 | "Connection: keep-alive\r\n" |
| 9526 | "referer: www.foo.com\r\n" |
| 9527 | "hEllo: Kitty\r\n" |
| 9528 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9529 | }; |
| 9530 | |
| 9531 | // Lastly, the server responds with the actual content. |
| 9532 | MockRead data_reads[] = { |
| 9533 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9534 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9535 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9536 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9537 | }; |
| 9538 | |
| 9539 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9540 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9541 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9542 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9543 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9545 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9547 | |
| 9548 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9549 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9550 | } |
| 9551 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9552 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9553 | HttpRequestInfo request; |
| 9554 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9555 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9556 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9557 | session_deps_.proxy_resolution_service = |
| 9558 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9559 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9560 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9561 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9563 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9564 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9565 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9566 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9567 | |
| 9568 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9569 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9570 | MockWrite( |
| 9571 | "GET / HTTP/1.1\r\n" |
| 9572 | "Host: www.example.org\r\n" |
| 9573 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9574 | |
| 9575 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9576 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9577 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9578 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9579 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9580 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9581 | }; |
| 9582 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9584 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9586 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9587 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9591 | |
| 9592 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9593 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9596 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9597 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9598 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9599 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9600 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9601 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9602 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9603 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9604 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9605 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9607 | EXPECT_EQ("Payload", response_text); |
| 9608 | } |
| 9609 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9610 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9611 | HttpRequestInfo request; |
| 9612 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9613 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9614 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9615 | session_deps_.proxy_resolution_service = |
| 9616 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9617 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9618 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9621 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9622 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9623 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9624 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9625 | |
| 9626 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9627 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9628 | arraysize(write_buffer)), |
| 9629 | MockWrite( |
| 9630 | "GET / HTTP/1.1\r\n" |
| 9631 | "Host: www.example.org\r\n" |
| 9632 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9633 | |
| 9634 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9635 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9636 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9637 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9639 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9640 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9641 | }; |
| 9642 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9643 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9644 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9646 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9647 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9648 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9650 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9651 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9652 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9654 | |
| 9655 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9656 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9657 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9658 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9659 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9660 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9661 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9663 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9664 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9665 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9666 | |
| 9667 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9668 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9669 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9670 | EXPECT_EQ("Payload", response_text); |
| 9671 | } |
| 9672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9673 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9674 | HttpRequestInfo request; |
| 9675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9676 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9677 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9678 | session_deps_.proxy_resolution_service = |
| 9679 | ProxyResolutionService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9680 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9681 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9685 | |
| 9686 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9687 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9688 | |
| 9689 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9690 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9691 | MockWrite( |
| 9692 | "GET / HTTP/1.1\r\n" |
| 9693 | "Host: www.example.org\r\n" |
| 9694 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9695 | |
| 9696 | MockRead data_reads[] = { |
| 9697 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9698 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9699 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9700 | MockRead("Payload"), |
| 9701 | MockRead(SYNCHRONOUS, OK) |
| 9702 | }; |
| 9703 | |
| 9704 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9705 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9707 | |
| 9708 | TestCompletionCallback callback; |
| 9709 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9712 | |
| 9713 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9714 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9716 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9717 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9718 | |
| 9719 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9720 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9721 | TestLoadTimingNotReused(load_timing_info, |
| 9722 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9723 | |
| 9724 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9725 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9726 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9727 | EXPECT_EQ("Payload", response_text); |
| 9728 | } |
| 9729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9730 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9731 | HttpRequestInfo request; |
| 9732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9733 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9734 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9735 | session_deps_.proxy_resolution_service = |
| 9736 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9737 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9738 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9739 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9740 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9741 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9742 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9743 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9744 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9745 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9746 | 0x05, // Version |
| 9747 | 0x01, // Command (CONNECT) |
| 9748 | 0x00, // Reserved. |
| 9749 | 0x03, // Address type (DOMAINNAME). |
| 9750 | 0x0F, // Length of domain (15) |
| 9751 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9752 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9753 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9754 | const char kSOCKS5OkResponse[] = |
| 9755 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9756 | |
| 9757 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9758 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9759 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9760 | MockWrite( |
| 9761 | "GET / HTTP/1.1\r\n" |
| 9762 | "Host: www.example.org\r\n" |
| 9763 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9764 | |
| 9765 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9766 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9767 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9768 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9769 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9770 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9771 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9772 | }; |
| 9773 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9774 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9775 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9778 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9779 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9780 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9782 | |
| 9783 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9784 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9785 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9786 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9787 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9788 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9789 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9790 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9791 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9792 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9793 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9794 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9795 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9796 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9797 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9798 | EXPECT_EQ("Payload", response_text); |
| 9799 | } |
| 9800 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9801 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9802 | HttpRequestInfo request; |
| 9803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9804 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9805 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9806 | session_deps_.proxy_resolution_service = |
| 9807 | ProxyResolutionService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9808 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9809 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9810 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9813 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9814 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9815 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9816 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9817 | 0x05, // Version |
| 9818 | 0x01, // Command (CONNECT) |
| 9819 | 0x00, // Reserved. |
| 9820 | 0x03, // Address type (DOMAINNAME). |
| 9821 | 0x0F, // Length of domain (15) |
| 9822 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9823 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9824 | }; |
| 9825 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9826 | const char kSOCKS5OkResponse[] = |
| 9827 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9828 | |
| 9829 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9830 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9831 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9832 | arraysize(kSOCKS5OkRequest)), |
| 9833 | MockWrite( |
| 9834 | "GET / HTTP/1.1\r\n" |
| 9835 | "Host: www.example.org\r\n" |
| 9836 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9837 | |
| 9838 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9839 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9840 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9841 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9842 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9843 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9844 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9845 | }; |
| 9846 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9847 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9848 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9850 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9851 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9852 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9854 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9858 | |
| 9859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9862 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9863 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9864 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9865 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9866 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9867 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9868 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9869 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9870 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9871 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9872 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9873 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9874 | EXPECT_EQ("Payload", response_text); |
| 9875 | } |
| 9876 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9877 | namespace { |
| 9878 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9879 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9880 | |
| 9881 | struct GroupNameTest { |
| 9882 | std::string proxy_server; |
| 9883 | std::string url; |
| 9884 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9885 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9886 | }; |
| 9887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9888 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9889 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9891 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9892 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9893 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9894 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9895 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9896 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9897 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9898 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9899 | |
| 9900 | return session; |
| 9901 | } |
| 9902 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9903 | int GroupNameTransactionHelper(const std::string& url, |
| 9904 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9905 | HttpRequestInfo request; |
| 9906 | request.method = "GET"; |
| 9907 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9910 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9911 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9912 | |
| 9913 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9914 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9915 | } |
| 9916 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9917 | } // namespace |
| 9918 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9919 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9920 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9921 | { |
| 9922 | "", // unused |
| 9923 | "http://www.example.org/direct", |
| 9924 | "www.example.org:80", |
| 9925 | false, |
| 9926 | }, |
| 9927 | { |
| 9928 | "", // unused |
| 9929 | "http://[2001:1418:13:1::25]/direct", |
| 9930 | "[2001:1418:13:1::25]:80", |
| 9931 | false, |
| 9932 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9933 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9934 | // SSL Tests |
| 9935 | { |
| 9936 | "", // unused |
| 9937 | "https://www.example.org/direct_ssl", |
| 9938 | "ssl/www.example.org:443", |
| 9939 | true, |
| 9940 | }, |
| 9941 | { |
| 9942 | "", // unused |
| 9943 | "https://[2001:1418:13:1::25]/direct", |
| 9944 | "ssl/[2001:1418:13:1::25]:443", |
| 9945 | true, |
| 9946 | }, |
| 9947 | { |
| 9948 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9949 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9950 | "ssl/host.with.alternate:443", |
| 9951 | true, |
| 9952 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9953 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9954 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9955 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9956 | session_deps_.proxy_resolution_service = |
| 9957 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9958 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9959 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9960 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9961 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9962 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9963 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9964 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9965 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9966 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9967 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9968 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9969 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9970 | |
| 9971 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9972 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9973 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9974 | EXPECT_EQ(tests[i].expected_group_name, |
| 9975 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9976 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9977 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9978 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 9979 | } |
| 9980 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 9981 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 9982 | // When SSL proxy is not in use, socket must be requested from |
| 9983 | // |transport_conn_pool|. |
| 9984 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9985 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9986 | } |
| 9987 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9988 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9989 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9990 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9991 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 9992 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9993 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9994 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9995 | // SSL Tests |
| 9996 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 9997 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 9998 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9999 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10000 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10001 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10002 | "http_proxy", "https://host.with.alternate/direct", |
| 10003 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10004 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10005 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10006 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10007 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10008 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10009 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10010 | }; |
| 10011 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10012 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10013 | session_deps_.proxy_resolution_service = |
| 10014 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10015 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10016 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10017 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10018 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10019 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10020 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10021 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10022 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10023 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10024 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10025 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10026 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10027 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10028 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10029 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10030 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10031 | |
| 10032 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10033 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10034 | if (tests[i].ssl) |
| 10035 | EXPECT_EQ(tests[i].expected_group_name, |
| 10036 | ssl_conn_pool->last_group_name_received()); |
| 10037 | else |
| 10038 | EXPECT_EQ(tests[i].expected_group_name, |
| 10039 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10040 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10041 | } |
| 10042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10043 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10044 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10045 | { |
| 10046 | "socks4://socks_proxy:1080", |
| 10047 | "http://www.example.org/socks4_direct", |
| 10048 | "socks4/www.example.org:80", |
| 10049 | false, |
| 10050 | }, |
| 10051 | { |
| 10052 | "socks5://socks_proxy:1080", |
| 10053 | "http://www.example.org/socks5_direct", |
| 10054 | "socks5/www.example.org:80", |
| 10055 | false, |
| 10056 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10057 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10058 | // SSL Tests |
| 10059 | { |
| 10060 | "socks4://socks_proxy:1080", |
| 10061 | "https://www.example.org/socks4_ssl", |
| 10062 | "socks4/ssl/www.example.org:443", |
| 10063 | true, |
| 10064 | }, |
| 10065 | { |
| 10066 | "socks5://socks_proxy:1080", |
| 10067 | "https://www.example.org/socks5_ssl", |
| 10068 | "socks5/ssl/www.example.org:443", |
| 10069 | true, |
| 10070 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10071 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10072 | { |
| 10073 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10074 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10075 | "socks4/ssl/host.with.alternate:443", |
| 10076 | true, |
| 10077 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10078 | }; |
| 10079 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10080 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10081 | session_deps_.proxy_resolution_service = |
| 10082 | ProxyResolutionService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10083 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10084 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10085 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10086 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10087 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10088 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10089 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10090 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10091 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10092 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10093 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10094 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10095 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10096 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10097 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10098 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10101 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10102 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10103 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10104 | if (tests[i].ssl) |
| 10105 | EXPECT_EQ(tests[i].expected_group_name, |
| 10106 | ssl_conn_pool->last_group_name_received()); |
| 10107 | else |
| 10108 | EXPECT_EQ(tests[i].expected_group_name, |
| 10109 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10110 | } |
| 10111 | } |
| 10112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10113 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10114 | HttpRequestInfo request; |
| 10115 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10116 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10117 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10118 | session_deps_.proxy_resolution_service = |
| 10119 | ProxyResolutionService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10120 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10121 | // This simulates failure resolving all hostnames; that means we will fail |
| 10122 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10123 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10124 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10128 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10129 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10130 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10132 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10133 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10134 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10135 | } |
| 10136 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10137 | // Base test to make sure that when the load flags for a request specify to |
| 10138 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10139 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10140 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10141 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10142 | HttpRequestInfo request_info; |
| 10143 | request_info.method = "GET"; |
| 10144 | request_info.load_flags = load_flags; |
| 10145 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10146 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10147 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10148 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10152 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10153 | // 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] | 10154 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10155 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10156 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10157 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10158 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10159 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10160 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10162 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10164 | |
| 10165 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10166 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10167 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10168 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10169 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10170 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10171 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10172 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10173 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10174 | // 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] | 10175 | // we can tell if the next lookup hit the cache, or the "network". |
| 10176 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10177 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10178 | |
| 10179 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10180 | // 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] | 10181 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10182 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10183 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10184 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10185 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10186 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10187 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10188 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10189 | |
| 10190 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10191 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10192 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10193 | } |
| 10194 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10195 | // There are multiple load flags that should trigger the host cache bypass. |
| 10196 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10197 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10198 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 10199 | } |
| 10200 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10201 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10202 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 10203 | } |
| 10204 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10205 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10206 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 10207 | } |
| 10208 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10209 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10210 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10211 | HttpRequestInfo request; |
| 10212 | request.method = "GET"; |
| 10213 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10214 | |
| 10215 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10216 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10217 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10218 | StaticSocketDataProvider data(NULL, 0, |
| 10219 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10221 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10223 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10227 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10229 | |
| 10230 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10231 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10232 | |
| 10233 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10234 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10235 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10236 | } |
| 10237 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10238 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10239 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10240 | HttpRequestInfo request; |
| 10241 | request.method = "GET"; |
| 10242 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10243 | |
| 10244 | MockRead data_reads[] = { |
| 10245 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10246 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10247 | }; |
| 10248 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10249 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10250 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10251 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10253 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10257 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10259 | |
| 10260 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10261 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10263 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10264 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10265 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10266 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10267 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10268 | |
| 10269 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10270 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10271 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10272 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10273 | |
| 10274 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10275 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10276 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10277 | } |
| 10278 | |
| 10279 | // Make sure that a dropped connection while draining the body for auth |
| 10280 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10281 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10282 | HttpRequestInfo request; |
| 10283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10284 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10285 | |
| 10286 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10287 | MockWrite( |
| 10288 | "GET / HTTP/1.1\r\n" |
| 10289 | "Host: www.example.org\r\n" |
| 10290 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10291 | }; |
| 10292 | |
| 10293 | MockRead data_reads1[] = { |
| 10294 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10295 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10296 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10297 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10298 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10299 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10300 | }; |
| 10301 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10302 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10303 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10304 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10306 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10307 | // be issuing -- the final header line contains the credentials. |
| 10308 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10309 | MockWrite( |
| 10310 | "GET / HTTP/1.1\r\n" |
| 10311 | "Host: www.example.org\r\n" |
| 10312 | "Connection: keep-alive\r\n" |
| 10313 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10314 | }; |
| 10315 | |
| 10316 | // Lastly, the server responds with the actual content. |
| 10317 | MockRead data_reads2[] = { |
| 10318 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10319 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10320 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10321 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10322 | }; |
| 10323 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10324 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10325 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10326 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10328 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10329 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10331 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10332 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10333 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10334 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10335 | |
| 10336 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10339 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10340 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10341 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10343 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10345 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10347 | |
| 10348 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10349 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10350 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10351 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10352 | ASSERT_TRUE(response); |
| 10353 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10354 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10355 | } |
| 10356 | |
| 10357 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10358 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10359 | session_deps_.proxy_resolution_service = |
| 10360 | ProxyResolutionService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10361 | |
| 10362 | HttpRequestInfo request; |
| 10363 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10364 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10365 | |
| 10366 | MockRead proxy_reads[] = { |
| 10367 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10368 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10369 | }; |
| 10370 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10371 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10372 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10373 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10374 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10377 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10378 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10379 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10380 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10382 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10386 | |
| 10387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10388 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10389 | } |
| 10390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10391 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10392 | HttpRequestInfo request; |
| 10393 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10394 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10395 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10398 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10399 | MockRead data_reads[] = { |
| 10400 | 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] | 10401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10402 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10403 | |
| 10404 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10407 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10409 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10411 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10412 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10414 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10415 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10417 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10418 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10419 | |
| 10420 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10421 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10422 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10423 | } |
| 10424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10425 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10426 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10427 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10428 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10429 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10430 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10431 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10432 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10433 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10434 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10435 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10436 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10437 | |
| 10438 | HttpRequestInfo request; |
| 10439 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10440 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10441 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10444 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10445 | |
| 10446 | MockRead data_reads[] = { |
| 10447 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10448 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10449 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10450 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10451 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10452 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10454 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10455 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10456 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10458 | |
| 10459 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10460 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10463 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10464 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10465 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10466 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10467 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10468 | } |
| 10469 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10470 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10471 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10472 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10473 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10474 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10475 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10476 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10477 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10479 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10480 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10481 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10482 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10483 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10484 | |
| 10485 | HttpRequestInfo request; |
| 10486 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10487 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10488 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10489 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10490 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10492 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10493 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10494 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10495 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10497 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10498 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10499 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10501 | |
| 10502 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10503 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10504 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10505 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10506 | } |
| 10507 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10508 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10509 | class FakeUploadElementReader : public UploadElementReader { |
| 10510 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10511 | FakeUploadElementReader() = default; |
| 10512 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10513 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10514 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10515 | |
| 10516 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10517 | int Init(CompletionOnceCallback callback) override { |
| 10518 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10519 | return ERR_IO_PENDING; |
| 10520 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10521 | uint64_t GetContentLength() const override { return 0; } |
| 10522 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10523 | int Read(IOBuffer* buf, |
| 10524 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10525 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10526 | return ERR_FAILED; |
| 10527 | } |
| 10528 | |
| 10529 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10530 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10531 | }; |
| 10532 | |
| 10533 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10534 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10535 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10536 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10537 | |
| 10538 | HttpRequestInfo request; |
| 10539 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10540 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10541 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10542 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10544 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10545 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10546 | |
| 10547 | StaticSocketDataProvider data; |
| 10548 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10549 | |
| 10550 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10551 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10553 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10554 | |
| 10555 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10556 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10557 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10558 | |
| 10559 | // Return Init()'s result after the transaction gets destroyed. |
| 10560 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame^] | 10561 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10562 | } |
| 10563 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10564 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10565 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10566 | HttpRequestInfo request; |
| 10567 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10568 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10569 | |
| 10570 | // First transaction will request a resource and receive a Basic challenge |
| 10571 | // with realm="first_realm". |
| 10572 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10573 | MockWrite( |
| 10574 | "GET / HTTP/1.1\r\n" |
| 10575 | "Host: www.example.org\r\n" |
| 10576 | "Connection: keep-alive\r\n" |
| 10577 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10578 | }; |
| 10579 | MockRead data_reads1[] = { |
| 10580 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10581 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10582 | "\r\n"), |
| 10583 | }; |
| 10584 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10585 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10586 | // for first_realm. The server will reject and provide a challenge with |
| 10587 | // second_realm. |
| 10588 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10589 | MockWrite( |
| 10590 | "GET / HTTP/1.1\r\n" |
| 10591 | "Host: www.example.org\r\n" |
| 10592 | "Connection: keep-alive\r\n" |
| 10593 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10594 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10595 | }; |
| 10596 | MockRead data_reads2[] = { |
| 10597 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10598 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10599 | "\r\n"), |
| 10600 | }; |
| 10601 | |
| 10602 | // This again fails, and goes back to first_realm. Make sure that the |
| 10603 | // entry is removed from cache. |
| 10604 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10605 | MockWrite( |
| 10606 | "GET / HTTP/1.1\r\n" |
| 10607 | "Host: www.example.org\r\n" |
| 10608 | "Connection: keep-alive\r\n" |
| 10609 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10610 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10611 | }; |
| 10612 | MockRead data_reads3[] = { |
| 10613 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10614 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10615 | "\r\n"), |
| 10616 | }; |
| 10617 | |
| 10618 | // Try one last time (with the correct password) and get the resource. |
| 10619 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10620 | MockWrite( |
| 10621 | "GET / HTTP/1.1\r\n" |
| 10622 | "Host: www.example.org\r\n" |
| 10623 | "Connection: keep-alive\r\n" |
| 10624 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10625 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10626 | }; |
| 10627 | MockRead data_reads4[] = { |
| 10628 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10629 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10630 | "Content-Length: 5\r\n" |
| 10631 | "\r\n" |
| 10632 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10633 | }; |
| 10634 | |
| 10635 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10636 | data_writes1, arraysize(data_writes1)); |
| 10637 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10638 | data_writes2, arraysize(data_writes2)); |
| 10639 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10640 | data_writes3, arraysize(data_writes3)); |
| 10641 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10642 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10643 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10644 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10645 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10646 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10648 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10652 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10653 | // Issue the first request with Authorize headers. There should be a |
| 10654 | // password prompt for first_realm waiting to be filled in after the |
| 10655 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10656 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10658 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10659 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10660 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10661 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10662 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10663 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10664 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10665 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10666 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10667 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10668 | |
| 10669 | // Issue the second request with an incorrect password. There should be a |
| 10670 | // password prompt for second_realm waiting to be filled in after the |
| 10671 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10672 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10673 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10674 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10675 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10676 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10677 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10678 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10679 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10680 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10681 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10682 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10683 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10684 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10685 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10686 | |
| 10687 | // Issue the third request with another incorrect password. There should be |
| 10688 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10689 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10690 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10691 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10692 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10693 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10695 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10696 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10697 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10698 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10699 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10700 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10701 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10702 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10703 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10704 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10705 | |
| 10706 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10707 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10708 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10709 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10711 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10712 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10713 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10714 | ASSERT_TRUE(response); |
| 10715 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10716 | } |
| 10717 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10718 | // Regression test for https://crbug.com/754395. |
| 10719 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10720 | MockRead data_reads[] = { |
| 10721 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10722 | MockRead(kAlternativeServiceHttpHeader), |
| 10723 | MockRead("\r\n"), |
| 10724 | MockRead("hello world"), |
| 10725 | MockRead(SYNCHRONOUS, OK), |
| 10726 | }; |
| 10727 | |
| 10728 | HttpRequestInfo request; |
| 10729 | request.method = "GET"; |
| 10730 | request.url = GURL("https://www.example.org/"); |
| 10731 | |
| 10732 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10734 | |
| 10735 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10736 | ssl.ssl_info.cert = |
| 10737 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10738 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 10739 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10741 | |
| 10742 | TestCompletionCallback callback; |
| 10743 | |
| 10744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10746 | |
| 10747 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10748 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10749 | |
| 10750 | url::SchemeHostPort test_server(request.url); |
| 10751 | HttpServerProperties* http_server_properties = |
| 10752 | session->http_server_properties(); |
| 10753 | EXPECT_TRUE( |
| 10754 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10755 | |
| 10756 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10757 | |
| 10758 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10759 | ASSERT_TRUE(response); |
| 10760 | ASSERT_TRUE(response->headers); |
| 10761 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10762 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10763 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10764 | |
| 10765 | std::string response_data; |
| 10766 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10767 | EXPECT_EQ("hello world", response_data); |
| 10768 | |
| 10769 | EXPECT_TRUE( |
| 10770 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10771 | } |
| 10772 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10773 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10774 | MockRead data_reads[] = { |
| 10775 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10776 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10777 | MockRead("\r\n"), |
| 10778 | MockRead("hello world"), |
| 10779 | MockRead(SYNCHRONOUS, OK), |
| 10780 | }; |
| 10781 | |
| 10782 | HttpRequestInfo request; |
| 10783 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10784 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10785 | |
| 10786 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10788 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10789 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10790 | ssl.ssl_info.cert = |
| 10791 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10792 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10794 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10795 | TestCompletionCallback callback; |
| 10796 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10798 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10799 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10800 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10802 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10803 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10804 | HttpServerProperties* http_server_properties = |
| 10805 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10806 | EXPECT_TRUE( |
| 10807 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10808 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10809 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10811 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10812 | ASSERT_TRUE(response); |
| 10813 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10814 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10815 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10816 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10817 | |
| 10818 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10819 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10820 | EXPECT_EQ("hello world", response_data); |
| 10821 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10822 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10823 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10824 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10825 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10826 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10827 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10828 | } |
| 10829 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10830 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10831 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10832 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10833 | MockRead data_reads[] = { |
| 10834 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10835 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10836 | MockRead("\r\n"), |
| 10837 | MockRead("hello world"), |
| 10838 | MockRead(SYNCHRONOUS, OK), |
| 10839 | }; |
| 10840 | |
| 10841 | HttpRequestInfo request; |
| 10842 | request.method = "GET"; |
| 10843 | request.url = GURL("http://www.example.org/"); |
| 10844 | request.load_flags = 0; |
| 10845 | |
| 10846 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10848 | |
| 10849 | TestCompletionCallback callback; |
| 10850 | |
| 10851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10853 | |
| 10854 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10855 | HttpServerProperties* http_server_properties = |
| 10856 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10857 | EXPECT_TRUE( |
| 10858 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10859 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10860 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10862 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10865 | ASSERT_TRUE(response); |
| 10866 | ASSERT_TRUE(response->headers); |
| 10867 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10868 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10869 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10870 | |
| 10871 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10872 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10873 | EXPECT_EQ("hello world", response_data); |
| 10874 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10875 | EXPECT_TRUE( |
| 10876 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10877 | } |
| 10878 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10879 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10880 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10881 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10882 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10883 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10884 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10885 | HttpRequestInfo request; |
| 10886 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10887 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10888 | request.load_flags = 0; |
| 10889 | |
| 10890 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10891 | StaticSocketDataProvider first_data; |
| 10892 | first_data.set_connect_data(mock_connect); |
| 10893 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10894 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10895 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10896 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10897 | |
| 10898 | MockRead data_reads[] = { |
| 10899 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10900 | MockRead(ASYNC, OK), |
| 10901 | }; |
| 10902 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10903 | 0); |
| 10904 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10905 | |
| 10906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10907 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10908 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10909 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10910 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10911 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10912 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10913 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10914 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10917 | TestCompletionCallback callback; |
| 10918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10920 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10921 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10922 | } |
| 10923 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10924 | // Regression test for https://crbug.com/615497: |
| 10925 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10926 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10927 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10928 | HttpRequestInfo request; |
| 10929 | request.method = "GET"; |
| 10930 | request.url = GURL("http://www.example.org/"); |
| 10931 | request.load_flags = 0; |
| 10932 | |
| 10933 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10934 | StaticSocketDataProvider first_data; |
| 10935 | first_data.set_connect_data(mock_connect); |
| 10936 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10937 | |
| 10938 | MockRead data_reads[] = { |
| 10939 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10940 | MockRead(ASYNC, OK), |
| 10941 | }; |
| 10942 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10943 | 0); |
| 10944 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10945 | |
| 10946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10947 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10948 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10949 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10950 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10951 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10952 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10953 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10955 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10956 | TestCompletionCallback callback; |
| 10957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10959 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10960 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10961 | } |
| 10962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10963 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10964 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10965 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10966 | HttpServerProperties* http_server_properties = |
| 10967 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10968 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10969 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10970 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10971 | http_server_properties->SetQuicAlternativeService( |
| 10972 | test_server, alternative_service, expiration, |
| 10973 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10974 | EXPECT_EQ( |
| 10975 | 1u, |
| 10976 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10977 | |
| 10978 | // Send a clear header. |
| 10979 | MockRead data_reads[] = { |
| 10980 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10981 | MockRead("Alt-Svc: clear\r\n"), |
| 10982 | MockRead("\r\n"), |
| 10983 | MockRead("hello world"), |
| 10984 | MockRead(SYNCHRONOUS, OK), |
| 10985 | }; |
| 10986 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10988 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10989 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10990 | ssl.ssl_info.cert = |
| 10991 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10992 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10994 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10995 | HttpRequestInfo request; |
| 10996 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10997 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10998 | |
| 10999 | TestCompletionCallback callback; |
| 11000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11001 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11004 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11007 | ASSERT_TRUE(response); |
| 11008 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11009 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11010 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11011 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11012 | |
| 11013 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11014 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11015 | EXPECT_EQ("hello world", response_data); |
| 11016 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11017 | EXPECT_TRUE( |
| 11018 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11019 | } |
| 11020 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11021 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11022 | MockRead data_reads[] = { |
| 11023 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11024 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11025 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11026 | MockRead("hello world"), |
| 11027 | MockRead(SYNCHRONOUS, OK), |
| 11028 | }; |
| 11029 | |
| 11030 | HttpRequestInfo request; |
| 11031 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11032 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11033 | |
| 11034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11035 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11036 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11037 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11038 | ssl.ssl_info.cert = |
| 11039 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11040 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11041 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11042 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11043 | TestCompletionCallback callback; |
| 11044 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11047 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11048 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11050 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11051 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11052 | HttpServerProperties* http_server_properties = |
| 11053 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11054 | EXPECT_TRUE( |
| 11055 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11057 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11059 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11060 | ASSERT_TRUE(response); |
| 11061 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11062 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11063 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11064 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11065 | |
| 11066 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11067 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11068 | EXPECT_EQ("hello world", response_data); |
| 11069 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11070 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11071 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11072 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11073 | |
| 11074 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11075 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11076 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11077 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11078 | 1234); |
| 11079 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11080 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11081 | } |
| 11082 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11083 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11084 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11085 | HostPortPair alternative("alternative.example.org", 443); |
| 11086 | std::string origin_url = "https://origin.example.org:443"; |
| 11087 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11088 | |
| 11089 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11090 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11091 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11092 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11093 | |
| 11094 | // HTTP/1.1 data for request. |
| 11095 | MockWrite http_writes[] = { |
| 11096 | MockWrite("GET / HTTP/1.1\r\n" |
| 11097 | "Host: alternative.example.org\r\n" |
| 11098 | "Connection: keep-alive\r\n\r\n"), |
| 11099 | }; |
| 11100 | |
| 11101 | MockRead http_reads[] = { |
| 11102 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11103 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11104 | "Content-Length: 40\r\n\r\n" |
| 11105 | "first HTTP/1.1 response from alternative"), |
| 11106 | }; |
| 11107 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11108 | http_writes, arraysize(http_writes)); |
| 11109 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11110 | |
| 11111 | StaticSocketDataProvider data_refused; |
| 11112 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11113 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11114 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11115 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11117 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11118 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11119 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11120 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11121 | http_server_properties->SetQuicAlternativeService( |
| 11122 | server, alternative_service, expiration, |
| 11123 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11124 | // Mark the QUIC alternative service as broken. |
| 11125 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11126 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11127 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11129 | request.method = "GET"; |
| 11130 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11131 | TestCompletionCallback callback; |
| 11132 | NetErrorDetails details; |
| 11133 | EXPECT_FALSE(details.quic_broken); |
| 11134 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11135 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11136 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11137 | EXPECT_TRUE(details.quic_broken); |
| 11138 | } |
| 11139 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11140 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11141 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11142 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11143 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11144 | std::string origin_url = "https://origin.example.org:443"; |
| 11145 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11146 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11147 | |
| 11148 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11149 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11150 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11152 | |
| 11153 | // HTTP/1.1 data for request. |
| 11154 | MockWrite http_writes[] = { |
| 11155 | MockWrite("GET / HTTP/1.1\r\n" |
| 11156 | "Host: alternative1.example.org\r\n" |
| 11157 | "Connection: keep-alive\r\n\r\n"), |
| 11158 | }; |
| 11159 | |
| 11160 | MockRead http_reads[] = { |
| 11161 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11162 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11163 | "Content-Length: 40\r\n\r\n" |
| 11164 | "first HTTP/1.1 response from alternative1"), |
| 11165 | }; |
| 11166 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11167 | http_writes, arraysize(http_writes)); |
| 11168 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11169 | |
| 11170 | StaticSocketDataProvider data_refused; |
| 11171 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11172 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11173 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11175 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11176 | session->http_server_properties(); |
| 11177 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11178 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11179 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11180 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11181 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11182 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11183 | alternative_service_info_vector.push_back( |
| 11184 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11185 | alternative_service1, expiration, |
| 11186 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11187 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11188 | alternative_service_info_vector.push_back( |
| 11189 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11190 | alternative_service2, expiration, |
| 11191 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11192 | |
| 11193 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11194 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11195 | |
| 11196 | // Mark one of the QUIC alternative service as broken. |
| 11197 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11198 | EXPECT_EQ(2u, |
| 11199 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11200 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11201 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11203 | request.method = "GET"; |
| 11204 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11205 | TestCompletionCallback callback; |
| 11206 | NetErrorDetails details; |
| 11207 | EXPECT_FALSE(details.quic_broken); |
| 11208 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11209 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11210 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11211 | EXPECT_FALSE(details.quic_broken); |
| 11212 | } |
| 11213 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11214 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11215 | HttpRequestInfo request; |
| 11216 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11217 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11218 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11219 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11220 | StaticSocketDataProvider first_data; |
| 11221 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11222 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11223 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11224 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11226 | |
| 11227 | MockRead data_reads[] = { |
| 11228 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11229 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11230 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11231 | }; |
| 11232 | StaticSocketDataProvider second_data( |
| 11233 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11234 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11235 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11237 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11238 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11239 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11240 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11241 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11242 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11243 | // Port is ignored by MockConnect anyway. |
| 11244 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11245 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11246 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11247 | http_server_properties->SetHttp2AlternativeService( |
| 11248 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11250 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11251 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11253 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11255 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11257 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11258 | ASSERT_TRUE(response); |
| 11259 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11260 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11261 | |
| 11262 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11263 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11264 | EXPECT_EQ("hello world", response_data); |
| 11265 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11266 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11267 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11268 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11269 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11270 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11271 | EXPECT_TRUE( |
| 11272 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11273 | } |
| 11274 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11275 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11276 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11277 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11278 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11279 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11280 | HttpRequestInfo restricted_port_request; |
| 11281 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11282 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11283 | restricted_port_request.load_flags = 0; |
| 11284 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11285 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11286 | StaticSocketDataProvider first_data; |
| 11287 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11288 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11289 | |
| 11290 | MockRead data_reads[] = { |
| 11291 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11292 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11293 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11294 | }; |
| 11295 | StaticSocketDataProvider second_data( |
| 11296 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11297 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11298 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11299 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11300 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11301 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11303 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11304 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11305 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11306 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11307 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11308 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11309 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11310 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11311 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11312 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11313 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11314 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11315 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11317 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11318 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11320 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11321 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11322 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11323 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11324 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11325 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11326 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11327 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11328 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11329 | |
| 11330 | HttpRequestInfo restricted_port_request; |
| 11331 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11332 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11333 | restricted_port_request.load_flags = 0; |
| 11334 | |
| 11335 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11336 | StaticSocketDataProvider first_data; |
| 11337 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11338 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11339 | |
| 11340 | MockRead data_reads[] = { |
| 11341 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11342 | MockRead("hello world"), |
| 11343 | MockRead(ASYNC, OK), |
| 11344 | }; |
| 11345 | StaticSocketDataProvider second_data( |
| 11346 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11347 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11348 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11349 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11350 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11353 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11354 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11355 | session->http_server_properties(); |
| 11356 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11357 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11358 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11359 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11360 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11361 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11362 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11363 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11365 | TestCompletionCallback callback; |
| 11366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11367 | EXPECT_EQ(ERR_IO_PENDING, |
| 11368 | trans.Start(&restricted_port_request, callback.callback(), |
| 11369 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11370 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11371 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11372 | } |
| 11373 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11374 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11375 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11376 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11377 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11378 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11379 | HttpRequestInfo restricted_port_request; |
| 11380 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11381 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11382 | restricted_port_request.load_flags = 0; |
| 11383 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11384 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11385 | StaticSocketDataProvider first_data; |
| 11386 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11387 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11388 | |
| 11389 | MockRead data_reads[] = { |
| 11390 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11391 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11392 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11393 | }; |
| 11394 | StaticSocketDataProvider second_data( |
| 11395 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11396 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11397 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11398 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11400 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11402 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11403 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11404 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11405 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11406 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11407 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11408 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11409 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11410 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11411 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11414 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11415 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11416 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11417 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11419 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11420 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11421 | } |
| 11422 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11423 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11424 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11425 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11426 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11427 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11428 | HttpRequestInfo unrestricted_port_request; |
| 11429 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11430 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11431 | unrestricted_port_request.load_flags = 0; |
| 11432 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11433 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11434 | StaticSocketDataProvider first_data; |
| 11435 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11436 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11437 | |
| 11438 | MockRead data_reads[] = { |
| 11439 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11440 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11441 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11442 | }; |
| 11443 | StaticSocketDataProvider second_data( |
| 11444 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11445 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11446 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11447 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11451 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11452 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11453 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11454 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11455 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11456 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11457 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11458 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11459 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11460 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11463 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11465 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11466 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11468 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11469 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11470 | } |
| 11471 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11472 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11473 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11474 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11475 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11476 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11477 | HttpRequestInfo unrestricted_port_request; |
| 11478 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11479 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11480 | unrestricted_port_request.load_flags = 0; |
| 11481 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11482 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11483 | StaticSocketDataProvider first_data; |
| 11484 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11485 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11486 | |
| 11487 | MockRead data_reads[] = { |
| 11488 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11489 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11490 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11491 | }; |
| 11492 | StaticSocketDataProvider second_data( |
| 11493 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11494 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11495 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11496 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11497 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11498 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11500 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11501 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11502 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11503 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11504 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11505 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11506 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11507 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11508 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11509 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11511 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11512 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11514 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11515 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11517 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11518 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11519 | } |
| 11520 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11521 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11522 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11523 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11524 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11525 | HttpRequestInfo request; |
| 11526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11527 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11528 | |
| 11529 | // The alternate protocol request will error out before we attempt to connect, |
| 11530 | // so only the standard HTTP request will try to connect. |
| 11531 | MockRead data_reads[] = { |
| 11532 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11533 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11534 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11535 | }; |
| 11536 | StaticSocketDataProvider data( |
| 11537 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11538 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11541 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11542 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11543 | session->http_server_properties(); |
| 11544 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11545 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11546 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11547 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11548 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11549 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11552 | TestCompletionCallback callback; |
| 11553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11556 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11557 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11559 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11560 | ASSERT_TRUE(response); |
| 11561 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11562 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11563 | |
| 11564 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11565 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11566 | EXPECT_EQ("hello world", response_data); |
| 11567 | } |
| 11568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11569 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11570 | HttpRequestInfo request; |
| 11571 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11572 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11573 | |
| 11574 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11575 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11576 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11577 | MockRead("\r\n"), |
| 11578 | MockRead("hello world"), |
| 11579 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11580 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11581 | |
| 11582 | StaticSocketDataProvider first_transaction( |
| 11583 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11584 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11585 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11586 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11588 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11589 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11590 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11591 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11592 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11593 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11594 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11595 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11596 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11597 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11598 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11599 | }; |
| 11600 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11601 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11602 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11603 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11604 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11605 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11606 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11607 | NULL, 0, NULL, 0); |
| 11608 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11609 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11610 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11611 | &hanging_non_alternate_protocol_socket); |
| 11612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11613 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11614 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11615 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11616 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11617 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11618 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11619 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11620 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11621 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11622 | |
| 11623 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11624 | ASSERT_TRUE(response); |
| 11625 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11626 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11627 | |
| 11628 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11629 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11630 | EXPECT_EQ("hello world", response_data); |
| 11631 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11632 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11633 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11635 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11637 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11638 | |
| 11639 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11640 | ASSERT_TRUE(response); |
| 11641 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11642 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11643 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11644 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11645 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11646 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11647 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11648 | } |
| 11649 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11650 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11651 | HttpRequestInfo request; |
| 11652 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11653 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11654 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11655 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11656 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11657 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11658 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11659 | MockRead("\r\n"), |
| 11660 | MockRead("hello world"), |
| 11661 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11662 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11663 | }; |
| 11664 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11665 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11666 | 0); |
| 11667 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11668 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11669 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11670 | ssl_http11.ssl_info.cert = |
| 11671 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11672 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11673 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11674 | |
| 11675 | // Second transaction starts an alternative and a non-alternative Job. |
| 11676 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11677 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11678 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11679 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11680 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11681 | |
| 11682 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11683 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11684 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11685 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11686 | // Third transaction starts an alternative and a non-alternative job. |
| 11687 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11688 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11689 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11690 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11691 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11692 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11693 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11694 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11695 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11696 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11697 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11698 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11699 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11700 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11701 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11702 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11703 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11704 | }; |
| 11705 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11706 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11707 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11708 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11709 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11710 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11711 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11712 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11713 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11714 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11717 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11718 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11719 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11720 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11721 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11722 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11723 | |
| 11724 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11725 | ASSERT_TRUE(response); |
| 11726 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11727 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11728 | |
| 11729 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11730 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11731 | EXPECT_EQ("hello world", response_data); |
| 11732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11733 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11734 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11735 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11738 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11739 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11740 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11742 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11743 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11744 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11745 | |
| 11746 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11747 | ASSERT_TRUE(response); |
| 11748 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11749 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11750 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11751 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11752 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11753 | EXPECT_EQ("hello!", response_data); |
| 11754 | |
| 11755 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11756 | ASSERT_TRUE(response); |
| 11757 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11758 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11759 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11760 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11761 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11762 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11763 | } |
| 11764 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11765 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11766 | HttpRequestInfo request; |
| 11767 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11768 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11769 | |
| 11770 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11771 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11772 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11773 | MockRead("\r\n"), |
| 11774 | MockRead("hello world"), |
| 11775 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11776 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11777 | }; |
| 11778 | |
| 11779 | StaticSocketDataProvider first_transaction( |
| 11780 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11781 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11782 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11783 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11784 | ssl.ssl_info.cert = |
| 11785 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11786 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11788 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11789 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11790 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11791 | NULL, 0, NULL, 0); |
| 11792 | hanging_alternate_protocol_socket.set_connect_data( |
| 11793 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11794 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11795 | &hanging_alternate_protocol_socket); |
| 11796 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11797 | // 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] | 11798 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11799 | NULL, 0); |
| 11800 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11803 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11804 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11805 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11806 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11807 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11808 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11809 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11811 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11812 | |
| 11813 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11814 | ASSERT_TRUE(response); |
| 11815 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11816 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11817 | |
| 11818 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11819 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11820 | EXPECT_EQ("hello world", response_data); |
| 11821 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11822 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11823 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11825 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11827 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11828 | |
| 11829 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11830 | ASSERT_TRUE(response); |
| 11831 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11832 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11833 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11834 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11835 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11836 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11837 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11838 | } |
| 11839 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11840 | class CapturingProxyResolver : public ProxyResolver { |
| 11841 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11842 | CapturingProxyResolver() = default; |
| 11843 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11844 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11845 | int GetProxyForURL(const GURL& url, |
| 11846 | ProxyInfo* results, |
| 11847 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11848 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11849 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11850 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11851 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11852 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11853 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11854 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11855 | } |
| 11856 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11857 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11858 | |
| 11859 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11860 | std::vector<GURL> resolved_; |
| 11861 | |
| 11862 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11863 | }; |
| 11864 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11865 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11866 | public: |
| 11867 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11868 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11869 | |
| 11870 | int CreateProxyResolver( |
| 11871 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11872 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11873 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11874 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11875 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11876 | return OK; |
| 11877 | } |
| 11878 | |
| 11879 | private: |
| 11880 | ProxyResolver* resolver_; |
| 11881 | }; |
| 11882 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11883 | // Test that proxy is resolved using the origin url, |
| 11884 | // regardless of the alternative server. |
| 11885 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11886 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11887 | ProxyConfig proxy_config; |
| 11888 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11889 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11890 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11891 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11892 | |
| 11893 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11894 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11895 | &capturing_proxy_resolver); |
| 11896 | |
| 11897 | TestNetLog net_log; |
| 11898 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11899 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11900 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11901 | &net_log); |
| 11902 | |
| 11903 | session_deps_.net_log = &net_log; |
| 11904 | |
| 11905 | // Configure alternative service with a hostname that is not bypassed by the |
| 11906 | // proxy. |
| 11907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11908 | HttpServerProperties* http_server_properties = |
| 11909 | session->http_server_properties(); |
| 11910 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11911 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11912 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11913 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11914 | http_server_properties->SetHttp2AlternativeService( |
| 11915 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11916 | |
| 11917 | // Non-alternative job should hang. |
| 11918 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11919 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11920 | nullptr, 0); |
| 11921 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11922 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11923 | &hanging_alternate_protocol_socket); |
| 11924 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11925 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11926 | |
| 11927 | HttpRequestInfo request; |
| 11928 | request.method = "GET"; |
| 11929 | request.url = GURL("https://www.example.org/"); |
| 11930 | request.load_flags = 0; |
| 11931 | |
| 11932 | SpdySerializedFrame req( |
| 11933 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11934 | |
| 11935 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11936 | |
| 11937 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11938 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11939 | MockRead spdy_reads[] = { |
| 11940 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11941 | }; |
| 11942 | |
| 11943 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11944 | arraysize(spdy_writes)); |
| 11945 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11946 | |
| 11947 | TestCompletionCallback callback; |
| 11948 | |
| 11949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11950 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11951 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11952 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11953 | |
| 11954 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11955 | ASSERT_TRUE(response); |
| 11956 | ASSERT_TRUE(response->headers); |
| 11957 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11958 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11959 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11960 | |
| 11961 | std::string response_data; |
| 11962 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11963 | EXPECT_EQ("hello!", response_data); |
| 11964 | |
| 11965 | // Origin host bypasses proxy, no resolution should have happened. |
| 11966 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11967 | } |
| 11968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11969 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11970 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11971 | proxy_config.set_auto_detect(true); |
| 11972 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11973 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11974 | CapturingProxyResolver capturing_proxy_resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11975 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11976 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11977 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11978 | &capturing_proxy_resolver), |
| 11979 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11980 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11981 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11982 | |
| 11983 | HttpRequestInfo request; |
| 11984 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11985 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11986 | |
| 11987 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11988 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11989 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11990 | MockRead("\r\n"), |
| 11991 | MockRead("hello world"), |
| 11992 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11993 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11994 | }; |
| 11995 | |
| 11996 | StaticSocketDataProvider first_transaction( |
| 11997 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11998 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11999 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12000 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12002 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12003 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12004 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12005 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12006 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12007 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12008 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12009 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12010 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12011 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12012 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12013 | }; |
| 12014 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12015 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12016 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12017 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12018 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12019 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12020 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12021 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12022 | }; |
| 12023 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12024 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12025 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12026 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12027 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12028 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12029 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 12030 | NULL, 0, NULL, 0); |
| 12031 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12032 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12033 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12034 | &hanging_non_alternate_protocol_socket); |
| 12035 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12036 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12037 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12039 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12040 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12041 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12042 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12044 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12045 | |
| 12046 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12047 | ASSERT_TRUE(response); |
| 12048 | ASSERT_TRUE(response->headers); |
| 12049 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12050 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12051 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12052 | |
| 12053 | std::string response_data; |
| 12054 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12055 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12056 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12057 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12058 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12059 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12060 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12062 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12063 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12064 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12065 | ASSERT_TRUE(response); |
| 12066 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12067 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12068 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12069 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12070 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12071 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12072 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12073 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12074 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12075 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12076 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12077 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12078 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12079 | LoadTimingInfo load_timing_info; |
| 12080 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12081 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12082 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12083 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12084 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12085 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12086 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12087 | HttpRequestInfo request; |
| 12088 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12089 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12090 | |
| 12091 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12092 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12093 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12094 | MockRead("\r\n"), |
| 12095 | MockRead("hello world"), |
| 12096 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12097 | }; |
| 12098 | |
| 12099 | StaticSocketDataProvider first_transaction( |
| 12100 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12101 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12102 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12103 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12104 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12105 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12106 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12107 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12108 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12109 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12110 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12111 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12112 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12113 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12114 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12115 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12116 | }; |
| 12117 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12118 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12119 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12120 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12121 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12122 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12125 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12128 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12129 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12131 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12132 | |
| 12133 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12134 | ASSERT_TRUE(response); |
| 12135 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12136 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12137 | |
| 12138 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12139 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12140 | EXPECT_EQ("hello world", response_data); |
| 12141 | |
| 12142 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12143 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12144 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12145 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12146 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12147 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12148 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12149 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12150 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12151 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12152 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12154 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12155 | |
| 12156 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12157 | ASSERT_TRUE(response); |
| 12158 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12159 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12160 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12161 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12162 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12163 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12164 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12165 | } |
| 12166 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12167 | // GenerateAuthToken is a mighty big test. |
| 12168 | // It tests all permutation of GenerateAuthToken behavior: |
| 12169 | // - Synchronous and Asynchronous completion. |
| 12170 | // - OK or error on completion. |
| 12171 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12172 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12173 | // - Non-authenticating and authenticating backend. |
| 12174 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12175 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12176 | // problems generating an auth token for an authenticating proxy, we don't |
| 12177 | // need to test all permutations of the backend server). |
| 12178 | // |
| 12179 | // The test proceeds by going over each of the configuration cases, and |
| 12180 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12181 | // specifies both the configuration for the test as well as the expectations |
| 12182 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12183 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12184 | static const char kServer[] = "http://www.example.com"; |
| 12185 | static const char kSecureServer[] = "https://www.example.com"; |
| 12186 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12187 | |
| 12188 | enum AuthTiming { |
| 12189 | AUTH_NONE, |
| 12190 | AUTH_SYNC, |
| 12191 | AUTH_ASYNC, |
| 12192 | }; |
| 12193 | |
| 12194 | const MockWrite kGet( |
| 12195 | "GET / HTTP/1.1\r\n" |
| 12196 | "Host: www.example.com\r\n" |
| 12197 | "Connection: keep-alive\r\n\r\n"); |
| 12198 | const MockWrite kGetProxy( |
| 12199 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12200 | "Host: www.example.com\r\n" |
| 12201 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12202 | const MockWrite kGetAuth( |
| 12203 | "GET / HTTP/1.1\r\n" |
| 12204 | "Host: www.example.com\r\n" |
| 12205 | "Connection: keep-alive\r\n" |
| 12206 | "Authorization: auth_token\r\n\r\n"); |
| 12207 | const MockWrite kGetProxyAuth( |
| 12208 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12209 | "Host: www.example.com\r\n" |
| 12210 | "Proxy-Connection: keep-alive\r\n" |
| 12211 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12212 | const MockWrite kGetAuthThroughProxy( |
| 12213 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12214 | "Host: www.example.com\r\n" |
| 12215 | "Proxy-Connection: keep-alive\r\n" |
| 12216 | "Authorization: auth_token\r\n\r\n"); |
| 12217 | const MockWrite kGetAuthWithProxyAuth( |
| 12218 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12219 | "Host: www.example.com\r\n" |
| 12220 | "Proxy-Connection: keep-alive\r\n" |
| 12221 | "Proxy-Authorization: auth_token\r\n" |
| 12222 | "Authorization: auth_token\r\n\r\n"); |
| 12223 | const MockWrite kConnect( |
| 12224 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12225 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12226 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12227 | const MockWrite kConnectProxyAuth( |
| 12228 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12229 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12230 | "Proxy-Connection: keep-alive\r\n" |
| 12231 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12232 | |
| 12233 | const MockRead kSuccess( |
| 12234 | "HTTP/1.1 200 OK\r\n" |
| 12235 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12236 | "Content-Length: 3\r\n\r\n" |
| 12237 | "Yes"); |
| 12238 | const MockRead kFailure( |
| 12239 | "Should not be called."); |
| 12240 | const MockRead kServerChallenge( |
| 12241 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12242 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12243 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12244 | "Content-Length: 14\r\n\r\n" |
| 12245 | "Unauthorized\r\n"); |
| 12246 | const MockRead kProxyChallenge( |
| 12247 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12248 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12249 | "Proxy-Connection: close\r\n" |
| 12250 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12251 | "Content-Length: 14\r\n\r\n" |
| 12252 | "Unauthorized\r\n"); |
| 12253 | const MockRead kProxyConnected( |
| 12254 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12255 | |
| 12256 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12257 | // no constructors, but the C++ compiler on Windows warns about |
| 12258 | // unspecified data in compound literals. So, moved to using constructors, |
| 12259 | // and TestRound's created with the default constructor should not be used. |
| 12260 | struct TestRound { |
| 12261 | TestRound() |
| 12262 | : expected_rv(ERR_UNEXPECTED), |
| 12263 | extra_write(NULL), |
| 12264 | extra_read(NULL) { |
| 12265 | } |
| 12266 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12267 | int expected_rv_arg) |
| 12268 | : write(write_arg), |
| 12269 | read(read_arg), |
| 12270 | expected_rv(expected_rv_arg), |
| 12271 | extra_write(NULL), |
| 12272 | extra_read(NULL) { |
| 12273 | } |
| 12274 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12275 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12276 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12277 | : write(write_arg), |
| 12278 | read(read_arg), |
| 12279 | expected_rv(expected_rv_arg), |
| 12280 | extra_write(extra_write_arg), |
| 12281 | extra_read(extra_read_arg) { |
| 12282 | } |
| 12283 | MockWrite write; |
| 12284 | MockRead read; |
| 12285 | int expected_rv; |
| 12286 | const MockWrite* extra_write; |
| 12287 | const MockRead* extra_read; |
| 12288 | }; |
| 12289 | |
| 12290 | static const int kNoSSL = 500; |
| 12291 | |
| 12292 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12293 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12294 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12295 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12296 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12297 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12298 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12299 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12300 | int num_auth_rounds; |
| 12301 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12302 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12303 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12304 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12305 | {__LINE__, |
| 12306 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12307 | AUTH_NONE, |
| 12308 | OK, |
| 12309 | kServer, |
| 12310 | AUTH_NONE, |
| 12311 | OK, |
| 12312 | 1, |
| 12313 | kNoSSL, |
| 12314 | {TestRound(kGet, kSuccess, OK)}}, |
| 12315 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12316 | {__LINE__, |
| 12317 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12318 | AUTH_NONE, |
| 12319 | OK, |
| 12320 | kServer, |
| 12321 | AUTH_SYNC, |
| 12322 | OK, |
| 12323 | 2, |
| 12324 | kNoSSL, |
| 12325 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12326 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12327 | {__LINE__, |
| 12328 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12329 | AUTH_NONE, |
| 12330 | OK, |
| 12331 | kServer, |
| 12332 | AUTH_SYNC, |
| 12333 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12334 | 3, |
| 12335 | kNoSSL, |
| 12336 | {TestRound(kGet, kServerChallenge, OK), |
| 12337 | TestRound(kGet, kServerChallenge, OK), |
| 12338 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12339 | {__LINE__, |
| 12340 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12341 | AUTH_NONE, |
| 12342 | OK, |
| 12343 | kServer, |
| 12344 | AUTH_SYNC, |
| 12345 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12346 | 2, |
| 12347 | kNoSSL, |
| 12348 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12349 | {__LINE__, |
| 12350 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12351 | AUTH_NONE, |
| 12352 | OK, |
| 12353 | kServer, |
| 12354 | AUTH_SYNC, |
| 12355 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12356 | 2, |
| 12357 | kNoSSL, |
| 12358 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12359 | {__LINE__, |
| 12360 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12361 | AUTH_SYNC, |
| 12362 | ERR_FAILED, |
| 12363 | kServer, |
| 12364 | AUTH_NONE, |
| 12365 | OK, |
| 12366 | 2, |
| 12367 | kNoSSL, |
| 12368 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12369 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12370 | {__LINE__, |
| 12371 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12372 | AUTH_ASYNC, |
| 12373 | ERR_FAILED, |
| 12374 | kServer, |
| 12375 | AUTH_NONE, |
| 12376 | OK, |
| 12377 | 2, |
| 12378 | kNoSSL, |
| 12379 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12380 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12381 | {__LINE__, |
| 12382 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12383 | AUTH_NONE, |
| 12384 | OK, |
| 12385 | kServer, |
| 12386 | AUTH_SYNC, |
| 12387 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12388 | 2, |
| 12389 | kNoSSL, |
| 12390 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12391 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12392 | {__LINE__, |
| 12393 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12394 | AUTH_NONE, |
| 12395 | OK, |
| 12396 | kServer, |
| 12397 | AUTH_ASYNC, |
| 12398 | ERR_FAILED, |
| 12399 | 2, |
| 12400 | kNoSSL, |
| 12401 | {TestRound(kGet, kServerChallenge, OK), |
| 12402 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12403 | {__LINE__, |
| 12404 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12405 | AUTH_NONE, |
| 12406 | OK, |
| 12407 | kServer, |
| 12408 | AUTH_ASYNC, |
| 12409 | OK, |
| 12410 | 2, |
| 12411 | kNoSSL, |
| 12412 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12413 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12414 | {__LINE__, |
| 12415 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12416 | AUTH_NONE, |
| 12417 | OK, |
| 12418 | kServer, |
| 12419 | AUTH_ASYNC, |
| 12420 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12421 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12422 | kNoSSL, |
| 12423 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12424 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12425 | TestRound(kGet, kServerChallenge, OK), |
| 12426 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12427 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12428 | {__LINE__, |
| 12429 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12430 | AUTH_NONE, |
| 12431 | OK, |
| 12432 | kServer, |
| 12433 | AUTH_NONE, |
| 12434 | OK, |
| 12435 | 1, |
| 12436 | kNoSSL, |
| 12437 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12438 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12439 | {__LINE__, |
| 12440 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12441 | AUTH_NONE, |
| 12442 | OK, |
| 12443 | kServer, |
| 12444 | AUTH_SYNC, |
| 12445 | OK, |
| 12446 | 2, |
| 12447 | kNoSSL, |
| 12448 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12449 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12450 | {__LINE__, |
| 12451 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12452 | AUTH_NONE, |
| 12453 | OK, |
| 12454 | kServer, |
| 12455 | AUTH_SYNC, |
| 12456 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12457 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12458 | kNoSSL, |
| 12459 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12460 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12461 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12462 | {__LINE__, |
| 12463 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12464 | AUTH_NONE, |
| 12465 | OK, |
| 12466 | kServer, |
| 12467 | AUTH_ASYNC, |
| 12468 | OK, |
| 12469 | 2, |
| 12470 | kNoSSL, |
| 12471 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12472 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12473 | {__LINE__, |
| 12474 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12475 | AUTH_NONE, |
| 12476 | OK, |
| 12477 | kServer, |
| 12478 | AUTH_ASYNC, |
| 12479 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12480 | 2, |
| 12481 | kNoSSL, |
| 12482 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12483 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12484 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12485 | {__LINE__, |
| 12486 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12487 | AUTH_SYNC, |
| 12488 | OK, |
| 12489 | kServer, |
| 12490 | AUTH_NONE, |
| 12491 | OK, |
| 12492 | 2, |
| 12493 | kNoSSL, |
| 12494 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12495 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12496 | {__LINE__, |
| 12497 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12498 | AUTH_SYNC, |
| 12499 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12500 | kServer, |
| 12501 | AUTH_NONE, |
| 12502 | OK, |
| 12503 | 2, |
| 12504 | kNoSSL, |
| 12505 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12506 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12507 | {__LINE__, |
| 12508 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12509 | AUTH_ASYNC, |
| 12510 | OK, |
| 12511 | kServer, |
| 12512 | AUTH_NONE, |
| 12513 | OK, |
| 12514 | 2, |
| 12515 | kNoSSL, |
| 12516 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12517 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12518 | {__LINE__, |
| 12519 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12520 | AUTH_ASYNC, |
| 12521 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12522 | kServer, |
| 12523 | AUTH_NONE, |
| 12524 | OK, |
| 12525 | 2, |
| 12526 | kNoSSL, |
| 12527 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12528 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12529 | {__LINE__, |
| 12530 | kProxy, |
| 12531 | AUTH_ASYNC, |
| 12532 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12533 | kServer, |
| 12534 | AUTH_NONE, |
| 12535 | OK, |
| 12536 | 3, |
| 12537 | kNoSSL, |
| 12538 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12539 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12540 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12541 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12542 | {__LINE__, |
| 12543 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12544 | AUTH_SYNC, |
| 12545 | OK, |
| 12546 | kServer, |
| 12547 | AUTH_SYNC, |
| 12548 | OK, |
| 12549 | 3, |
| 12550 | kNoSSL, |
| 12551 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12552 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12553 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12554 | {__LINE__, |
| 12555 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12556 | AUTH_SYNC, |
| 12557 | OK, |
| 12558 | kServer, |
| 12559 | AUTH_SYNC, |
| 12560 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12561 | 3, |
| 12562 | kNoSSL, |
| 12563 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12564 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12565 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12566 | {__LINE__, |
| 12567 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12568 | AUTH_ASYNC, |
| 12569 | OK, |
| 12570 | kServer, |
| 12571 | AUTH_SYNC, |
| 12572 | OK, |
| 12573 | 3, |
| 12574 | kNoSSL, |
| 12575 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12576 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12577 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12578 | {__LINE__, |
| 12579 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12580 | AUTH_ASYNC, |
| 12581 | OK, |
| 12582 | kServer, |
| 12583 | AUTH_SYNC, |
| 12584 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12585 | 3, |
| 12586 | kNoSSL, |
| 12587 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12588 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12589 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12590 | {__LINE__, |
| 12591 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12592 | AUTH_SYNC, |
| 12593 | OK, |
| 12594 | kServer, |
| 12595 | AUTH_ASYNC, |
| 12596 | OK, |
| 12597 | 3, |
| 12598 | kNoSSL, |
| 12599 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12600 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12601 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12602 | {__LINE__, |
| 12603 | kProxy, |
| 12604 | AUTH_SYNC, |
| 12605 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12606 | kServer, |
| 12607 | AUTH_ASYNC, |
| 12608 | OK, |
| 12609 | 4, |
| 12610 | kNoSSL, |
| 12611 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12612 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12613 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12614 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12615 | {__LINE__, |
| 12616 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12617 | AUTH_SYNC, |
| 12618 | OK, |
| 12619 | kServer, |
| 12620 | AUTH_ASYNC, |
| 12621 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12622 | 3, |
| 12623 | kNoSSL, |
| 12624 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12625 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12626 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12627 | {__LINE__, |
| 12628 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12629 | AUTH_ASYNC, |
| 12630 | OK, |
| 12631 | kServer, |
| 12632 | AUTH_ASYNC, |
| 12633 | OK, |
| 12634 | 3, |
| 12635 | kNoSSL, |
| 12636 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12637 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12638 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12639 | {__LINE__, |
| 12640 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12641 | AUTH_ASYNC, |
| 12642 | OK, |
| 12643 | kServer, |
| 12644 | AUTH_ASYNC, |
| 12645 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12646 | 3, |
| 12647 | kNoSSL, |
| 12648 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12649 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12650 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12651 | {__LINE__, |
| 12652 | kProxy, |
| 12653 | AUTH_ASYNC, |
| 12654 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12655 | kServer, |
| 12656 | AUTH_ASYNC, |
| 12657 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12658 | 4, |
| 12659 | kNoSSL, |
| 12660 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12661 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12662 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12663 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12664 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12665 | {__LINE__, |
| 12666 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12667 | AUTH_NONE, |
| 12668 | OK, |
| 12669 | kSecureServer, |
| 12670 | AUTH_NONE, |
| 12671 | OK, |
| 12672 | 1, |
| 12673 | 0, |
| 12674 | {TestRound(kGet, kSuccess, OK)}}, |
| 12675 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12676 | {__LINE__, |
| 12677 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12678 | AUTH_NONE, |
| 12679 | OK, |
| 12680 | kSecureServer, |
| 12681 | AUTH_SYNC, |
| 12682 | OK, |
| 12683 | 2, |
| 12684 | 0, |
| 12685 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12686 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12687 | {__LINE__, |
| 12688 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12689 | AUTH_NONE, |
| 12690 | OK, |
| 12691 | kSecureServer, |
| 12692 | AUTH_SYNC, |
| 12693 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12694 | 2, |
| 12695 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12696 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12697 | {__LINE__, |
| 12698 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12699 | AUTH_NONE, |
| 12700 | OK, |
| 12701 | kSecureServer, |
| 12702 | AUTH_ASYNC, |
| 12703 | OK, |
| 12704 | 2, |
| 12705 | 0, |
| 12706 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12707 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12708 | {__LINE__, |
| 12709 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12710 | AUTH_NONE, |
| 12711 | OK, |
| 12712 | kSecureServer, |
| 12713 | AUTH_ASYNC, |
| 12714 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12715 | 2, |
| 12716 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12717 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12718 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12719 | {__LINE__, |
| 12720 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12721 | AUTH_NONE, |
| 12722 | OK, |
| 12723 | kSecureServer, |
| 12724 | AUTH_NONE, |
| 12725 | OK, |
| 12726 | 1, |
| 12727 | 0, |
| 12728 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12729 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12730 | {__LINE__, |
| 12731 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12732 | AUTH_NONE, |
| 12733 | OK, |
| 12734 | kSecureServer, |
| 12735 | AUTH_SYNC, |
| 12736 | OK, |
| 12737 | 2, |
| 12738 | 0, |
| 12739 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12740 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12741 | {__LINE__, |
| 12742 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12743 | AUTH_NONE, |
| 12744 | OK, |
| 12745 | kSecureServer, |
| 12746 | AUTH_SYNC, |
| 12747 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12748 | 2, |
| 12749 | 0, |
| 12750 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12751 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12752 | {__LINE__, |
| 12753 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12754 | AUTH_NONE, |
| 12755 | OK, |
| 12756 | kSecureServer, |
| 12757 | AUTH_ASYNC, |
| 12758 | OK, |
| 12759 | 2, |
| 12760 | 0, |
| 12761 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12762 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12763 | {__LINE__, |
| 12764 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12765 | AUTH_NONE, |
| 12766 | OK, |
| 12767 | kSecureServer, |
| 12768 | AUTH_ASYNC, |
| 12769 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12770 | 2, |
| 12771 | 0, |
| 12772 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12773 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12774 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12775 | {__LINE__, |
| 12776 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12777 | AUTH_SYNC, |
| 12778 | OK, |
| 12779 | kSecureServer, |
| 12780 | AUTH_NONE, |
| 12781 | OK, |
| 12782 | 2, |
| 12783 | 1, |
| 12784 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12785 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12786 | {__LINE__, |
| 12787 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12788 | AUTH_SYNC, |
| 12789 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12790 | kSecureServer, |
| 12791 | AUTH_NONE, |
| 12792 | OK, |
| 12793 | 2, |
| 12794 | kNoSSL, |
| 12795 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12796 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12797 | {__LINE__, |
| 12798 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12799 | AUTH_SYNC, |
| 12800 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12801 | kSecureServer, |
| 12802 | AUTH_NONE, |
| 12803 | OK, |
| 12804 | 2, |
| 12805 | kNoSSL, |
| 12806 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12807 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12808 | {__LINE__, |
| 12809 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12810 | AUTH_SYNC, |
| 12811 | ERR_UNEXPECTED, |
| 12812 | kSecureServer, |
| 12813 | AUTH_NONE, |
| 12814 | OK, |
| 12815 | 2, |
| 12816 | kNoSSL, |
| 12817 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12818 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12819 | {__LINE__, |
| 12820 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12821 | AUTH_ASYNC, |
| 12822 | OK, |
| 12823 | kSecureServer, |
| 12824 | AUTH_NONE, |
| 12825 | OK, |
| 12826 | 2, |
| 12827 | 1, |
| 12828 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12829 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12830 | {__LINE__, |
| 12831 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12832 | AUTH_ASYNC, |
| 12833 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12834 | kSecureServer, |
| 12835 | AUTH_NONE, |
| 12836 | OK, |
| 12837 | 2, |
| 12838 | kNoSSL, |
| 12839 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12840 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12841 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12842 | {__LINE__, |
| 12843 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12844 | AUTH_SYNC, |
| 12845 | OK, |
| 12846 | kSecureServer, |
| 12847 | AUTH_SYNC, |
| 12848 | OK, |
| 12849 | 3, |
| 12850 | 1, |
| 12851 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12852 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12853 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12854 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12855 | {__LINE__, |
| 12856 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12857 | AUTH_SYNC, |
| 12858 | OK, |
| 12859 | kSecureServer, |
| 12860 | AUTH_SYNC, |
| 12861 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12862 | 3, |
| 12863 | 1, |
| 12864 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12865 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12866 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12867 | TestRound(kGet, 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_ASYNC, |
| 12871 | OK, |
| 12872 | kSecureServer, |
| 12873 | AUTH_SYNC, |
| 12874 | OK, |
| 12875 | 3, |
| 12876 | 1, |
| 12877 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12878 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12879 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12880 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12881 | {__LINE__, |
| 12882 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12883 | AUTH_ASYNC, |
| 12884 | OK, |
| 12885 | kSecureServer, |
| 12886 | AUTH_SYNC, |
| 12887 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12888 | 3, |
| 12889 | 1, |
| 12890 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12891 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12892 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12893 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12894 | {__LINE__, |
| 12895 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12896 | AUTH_SYNC, |
| 12897 | OK, |
| 12898 | kSecureServer, |
| 12899 | AUTH_ASYNC, |
| 12900 | OK, |
| 12901 | 3, |
| 12902 | 1, |
| 12903 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12904 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12905 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12906 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12907 | {__LINE__, |
| 12908 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12909 | AUTH_SYNC, |
| 12910 | OK, |
| 12911 | kSecureServer, |
| 12912 | AUTH_ASYNC, |
| 12913 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12914 | 3, |
| 12915 | 1, |
| 12916 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12917 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12918 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12919 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12920 | {__LINE__, |
| 12921 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12922 | AUTH_ASYNC, |
| 12923 | OK, |
| 12924 | kSecureServer, |
| 12925 | AUTH_ASYNC, |
| 12926 | OK, |
| 12927 | 3, |
| 12928 | 1, |
| 12929 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12930 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12931 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12932 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12933 | {__LINE__, |
| 12934 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12935 | AUTH_ASYNC, |
| 12936 | OK, |
| 12937 | kSecureServer, |
| 12938 | AUTH_ASYNC, |
| 12939 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12940 | 3, |
| 12941 | 1, |
| 12942 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12943 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12944 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12945 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12946 | {__LINE__, |
| 12947 | kProxy, |
| 12948 | AUTH_ASYNC, |
| 12949 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12950 | kSecureServer, |
| 12951 | AUTH_ASYNC, |
| 12952 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12953 | 4, |
| 12954 | 2, |
| 12955 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12956 | TestRound(kConnect, kProxyChallenge, OK), |
| 12957 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12958 | &kServerChallenge), |
| 12959 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12960 | }; |
| 12961 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12962 | for (const auto& test_config : test_configs) { |
| 12963 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12964 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12965 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12966 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12967 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12968 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12969 | |
| 12970 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12971 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12972 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12973 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12974 | std::string auth_challenge = "Mock realm=proxy"; |
| 12975 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12976 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12977 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12978 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12979 | empty_ssl_info, origin, |
| 12980 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12981 | auth_handler->SetGenerateExpectation( |
| 12982 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12983 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12984 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12985 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12986 | } |
| 12987 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12988 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12989 | std::string auth_challenge = "Mock realm=server"; |
| 12990 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12991 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12992 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12993 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12994 | empty_ssl_info, origin, |
| 12995 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12996 | auth_handler->SetGenerateExpectation( |
| 12997 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12998 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12999 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13000 | |
| 13001 | // The second handler always succeeds. It should only be used where there |
| 13002 | // are multiple auth sessions for server auth in the same network |
| 13003 | // transaction using the same auth scheme. |
| 13004 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13005 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13006 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13007 | empty_ssl_info, origin, |
| 13008 | NetLogWithSource()); |
| 13009 | second_handler->SetGenerateExpectation(true, OK); |
| 13010 | auth_factory->AddMockHandler(second_handler.release(), |
| 13011 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13012 | } |
| 13013 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13014 | session_deps_.proxy_resolution_service = |
| 13015 | ProxyResolutionService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13016 | } else { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13017 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13018 | } |
| 13019 | |
| 13020 | HttpRequestInfo request; |
| 13021 | request.method = "GET"; |
| 13022 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13025 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13026 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13027 | |
| 13028 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13029 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13030 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13031 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13032 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13033 | |
| 13034 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13035 | mock_reads.back().push_back(read_write_round.read); |
| 13036 | mock_writes.back().push_back(read_write_round.write); |
| 13037 | |
| 13038 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13039 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13040 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13041 | mock_reads.push_back(std::vector<MockRead>()); |
| 13042 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13043 | } |
| 13044 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13045 | if (read_write_round.extra_read) { |
| 13046 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13047 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13048 | if (read_write_round.extra_write) { |
| 13049 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13050 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13051 | |
| 13052 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13053 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13054 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13055 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13056 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13058 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13059 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13060 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13061 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13062 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13063 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13064 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13065 | } |
| 13066 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13067 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13068 | // they are as well. |
| 13069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13070 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13071 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13072 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13073 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13074 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13075 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13076 | int rv; |
| 13077 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13078 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13079 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13080 | rv = trans.RestartWithAuth( |
| 13081 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13082 | } |
| 13083 | if (rv == ERR_IO_PENDING) |
| 13084 | rv = callback.WaitForResult(); |
| 13085 | |
| 13086 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13087 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13088 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13089 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13090 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13091 | continue; |
| 13092 | } |
| 13093 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13094 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13095 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13096 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13097 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13098 | } |
| 13099 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13100 | } |
| 13101 | } |
| 13102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13103 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13104 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13105 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13106 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13107 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13108 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13109 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13110 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13111 | |
| 13112 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13113 | auth_handler->set_connection_based(true); |
| 13114 | std::string auth_challenge = "Mock realm=server"; |
| 13115 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13116 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13117 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13118 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13119 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13120 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13121 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13122 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13123 | int rv = OK; |
| 13124 | const HttpResponseInfo* response = NULL; |
| 13125 | HttpRequestInfo request; |
| 13126 | request.method = "GET"; |
| 13127 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13128 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13130 | |
| 13131 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13132 | // to validate that the TCP socket is not released to the pool between |
| 13133 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13134 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13135 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13136 | 50, // Max sockets for pool |
| 13137 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13138 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13139 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13140 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13141 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13142 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13145 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13146 | |
| 13147 | const MockWrite kGet( |
| 13148 | "GET / HTTP/1.1\r\n" |
| 13149 | "Host: www.example.com\r\n" |
| 13150 | "Connection: keep-alive\r\n\r\n"); |
| 13151 | const MockWrite kGetAuth( |
| 13152 | "GET / HTTP/1.1\r\n" |
| 13153 | "Host: www.example.com\r\n" |
| 13154 | "Connection: keep-alive\r\n" |
| 13155 | "Authorization: auth_token\r\n\r\n"); |
| 13156 | |
| 13157 | const MockRead kServerChallenge( |
| 13158 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13159 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13160 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13161 | "Content-Length: 14\r\n\r\n" |
| 13162 | "Unauthorized\r\n"); |
| 13163 | const MockRead kSuccess( |
| 13164 | "HTTP/1.1 200 OK\r\n" |
| 13165 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13166 | "Content-Length: 3\r\n\r\n" |
| 13167 | "Yes"); |
| 13168 | |
| 13169 | MockWrite writes[] = { |
| 13170 | // First round |
| 13171 | kGet, |
| 13172 | // Second round |
| 13173 | kGetAuth, |
| 13174 | // Third round |
| 13175 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13176 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13177 | kGetAuth, |
| 13178 | // Competing request |
| 13179 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13180 | }; |
| 13181 | MockRead reads[] = { |
| 13182 | // First round |
| 13183 | kServerChallenge, |
| 13184 | // Second round |
| 13185 | kServerChallenge, |
| 13186 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13187 | kServerChallenge, |
| 13188 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13189 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13190 | // Competing response |
| 13191 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13192 | }; |
| 13193 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13194 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13195 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13196 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13197 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13198 | |
| 13199 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13200 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13201 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13202 | if (rv == ERR_IO_PENDING) |
| 13203 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13204 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13205 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13206 | ASSERT_TRUE(response); |
| 13207 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13208 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13209 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13210 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13211 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13212 | // In between rounds, another request comes in for the same domain. |
| 13213 | // It should not be able to grab the TCP socket that trans has already |
| 13214 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13215 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13216 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13217 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13218 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13220 | // callback_compete.WaitForResult at this point would stall forever, |
| 13221 | // since the HttpNetworkTransaction does not release the request back to |
| 13222 | // the pool until after authentication completes. |
| 13223 | |
| 13224 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13225 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13226 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13227 | if (rv == ERR_IO_PENDING) |
| 13228 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13229 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13230 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13231 | ASSERT_TRUE(response); |
| 13232 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13233 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13234 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13235 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13236 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13237 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13238 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13239 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13240 | if (rv == ERR_IO_PENDING) |
| 13241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13242 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13243 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13244 | ASSERT_TRUE(response); |
| 13245 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13246 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13247 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13248 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13249 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13250 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13251 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13252 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13253 | if (rv == ERR_IO_PENDING) |
| 13254 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13255 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13256 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13257 | ASSERT_TRUE(response); |
| 13258 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13259 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13260 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13261 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13262 | // auth handler should transition to a DONE state in concert with the remote |
| 13263 | // server. But that's not something we can test here with a mock handler. |
| 13264 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13265 | auth_handler->state()); |
| 13266 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13267 | // Read the body since the fourth round was successful. This will also |
| 13268 | // release the socket back to the pool. |
| 13269 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13270 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13271 | if (rv == ERR_IO_PENDING) |
| 13272 | rv = callback.WaitForResult(); |
| 13273 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13274 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13275 | EXPECT_EQ(0, rv); |
| 13276 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13277 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13278 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13279 | |
| 13280 | // The competing request can now finish. Wait for the headers and then |
| 13281 | // read the body. |
| 13282 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13283 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13284 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13285 | if (rv == ERR_IO_PENDING) |
| 13286 | rv = callback.WaitForResult(); |
| 13287 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13288 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13289 | EXPECT_EQ(0, rv); |
| 13290 | |
| 13291 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13292 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13293 | } |
| 13294 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13295 | // This tests the case that a request is issued via http instead of spdy after |
| 13296 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13297 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13298 | HttpRequestInfo request; |
| 13299 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13300 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13301 | |
| 13302 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13303 | MockWrite( |
| 13304 | "GET / HTTP/1.1\r\n" |
| 13305 | "Host: www.example.org\r\n" |
| 13306 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13307 | }; |
| 13308 | |
| 13309 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13310 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13311 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13312 | MockRead("\r\n"), |
| 13313 | MockRead("hello world"), |
| 13314 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13315 | }; |
| 13316 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13317 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13318 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13319 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13321 | |
| 13322 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13323 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13324 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13326 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13327 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13328 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13329 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13332 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13334 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13336 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13337 | ASSERT_TRUE(response); |
| 13338 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13339 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13340 | |
| 13341 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13342 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13343 | EXPECT_EQ("hello world", response_data); |
| 13344 | |
| 13345 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13346 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13347 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13348 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13349 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13350 | // immediate server closing of the socket. |
| 13351 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13352 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13353 | HttpRequestInfo request; |
| 13354 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13355 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13356 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13357 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13358 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13359 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13360 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13361 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13362 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13363 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13364 | |
| 13365 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13366 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13367 | }; |
| 13368 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13369 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13370 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13371 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13372 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13373 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13374 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13375 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13378 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13380 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13381 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13382 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13383 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13384 | // it gets it. This is needed since the auth handler may get destroyed |
| 13385 | // before we get a chance to query it. |
| 13386 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13387 | public: |
| 13388 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13389 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13390 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13391 | |
| 13392 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13393 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13394 | const HttpRequestInfo* request, |
| 13395 | const CompletionCallback& callback, |
| 13396 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13397 | *url_ = request->url; |
| 13398 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13399 | credentials, request, callback, auth_token); |
| 13400 | } |
| 13401 | |
| 13402 | private: |
| 13403 | GURL* url_; |
| 13404 | }; |
| 13405 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13406 | // Test that if we cancel the transaction as the connection is completing, that |
| 13407 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13408 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13409 | // Setup everything about the connection to complete synchronously, so that |
| 13410 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13411 | // for is the callback from the HttpStreamRequest. |
| 13412 | // Then cancel the transaction. |
| 13413 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13414 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13415 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13416 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13417 | MockRead(SYNCHRONOUS, "hello world"), |
| 13418 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13419 | }; |
| 13420 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13421 | HttpRequestInfo request; |
| 13422 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13423 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13424 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13425 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13426 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13427 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13428 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13429 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13430 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13431 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13432 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13434 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13435 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13436 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13437 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13439 | trans.reset(); // Cancel the transaction here. |
| 13440 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13441 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13442 | } |
| 13443 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13444 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13445 | // stream is drained properly and added back to the socket pool. The main |
| 13446 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13447 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13448 | // deleted. |
| 13449 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13450 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13451 | MockRead data_reads[] = { |
| 13452 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13453 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13454 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13455 | MockRead(ASYNC, "1"), |
| 13456 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13457 | // HttpNetworkTransaction has been deleted. |
| 13458 | MockRead(ASYNC, "2"), |
| 13459 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13460 | }; |
| 13461 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13463 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13465 | |
| 13466 | { |
| 13467 | HttpRequestInfo request; |
| 13468 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13469 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13470 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13472 | TestCompletionCallback callback; |
| 13473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13476 | callback.WaitForResult(); |
| 13477 | |
| 13478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13479 | ASSERT_TRUE(response); |
| 13480 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13481 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13482 | |
| 13483 | // The transaction and HttpRequestInfo are deleted. |
| 13484 | } |
| 13485 | |
| 13486 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13487 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13488 | |
| 13489 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13490 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13491 | } |
| 13492 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13493 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13494 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13495 | session_deps_.proxy_resolution_service = |
| 13496 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13497 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13498 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13500 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13501 | HttpRequestInfo request; |
| 13502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13503 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13504 | |
| 13505 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13506 | MockWrite( |
| 13507 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13508 | "Host: www.example.org\r\n" |
| 13509 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13510 | }; |
| 13511 | |
| 13512 | MockRead data_reads1[] = { |
| 13513 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13514 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13515 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13516 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13517 | }; |
| 13518 | |
| 13519 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13520 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13521 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13522 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13523 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13524 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13525 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13526 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13527 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13528 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13529 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13531 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13533 | |
| 13534 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13535 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13537 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13538 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13539 | |
| 13540 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13541 | EXPECT_EQ(200, response->headers->response_code()); |
| 13542 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13543 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13544 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13545 | HostPortPair::FromString("myproxy:70")), |
| 13546 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13547 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13548 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13549 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13550 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13551 | |
| 13552 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13553 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13554 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13555 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13556 | } |
| 13557 | |
| 13558 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13559 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13560 | session_deps_.proxy_resolution_service = |
| 13561 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13562 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13563 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13565 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13566 | HttpRequestInfo request; |
| 13567 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13568 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13569 | |
| 13570 | // Since we have proxy, should try to establish tunnel. |
| 13571 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13572 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13573 | "Host: www.example.org:443\r\n" |
| 13574 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13575 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13576 | MockWrite("GET / HTTP/1.1\r\n" |
| 13577 | "Host: www.example.org\r\n" |
| 13578 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13579 | }; |
| 13580 | |
| 13581 | MockRead data_reads1[] = { |
| 13582 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13583 | |
| 13584 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13585 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13586 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13587 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13588 | }; |
| 13589 | |
| 13590 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13591 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13592 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13593 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13594 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13596 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13599 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13600 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13601 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13602 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13604 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13606 | |
| 13607 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13608 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13609 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13610 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13611 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13612 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13613 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13614 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13615 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13616 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13617 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13620 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13621 | |
| 13622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13623 | EXPECT_EQ(200, response->headers->response_code()); |
| 13624 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13625 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13626 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13627 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13628 | HostPortPair::FromString("myproxy:70")), |
| 13629 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13630 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13631 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13632 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13633 | |
| 13634 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13635 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13636 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13637 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13638 | } |
| 13639 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13640 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13641 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13642 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13643 | session_deps_.proxy_resolution_service = |
| 13644 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13645 | BoundTestNetLog log; |
| 13646 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13648 | |
| 13649 | HttpRequestInfo request; |
| 13650 | request.method = "GET"; |
| 13651 | request.url = GURL("https://[::1]:443/"); |
| 13652 | |
| 13653 | // Since we have proxy, should try to establish tunnel. |
| 13654 | MockWrite data_writes1[] = { |
| 13655 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13656 | "Host: [::1]:443\r\n" |
| 13657 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13658 | |
| 13659 | MockWrite("GET / HTTP/1.1\r\n" |
| 13660 | "Host: [::1]\r\n" |
| 13661 | "Connection: keep-alive\r\n\r\n"), |
| 13662 | }; |
| 13663 | |
| 13664 | MockRead data_reads1[] = { |
| 13665 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13666 | |
| 13667 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13668 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13669 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13670 | MockRead(SYNCHRONOUS, OK), |
| 13671 | }; |
| 13672 | |
| 13673 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13674 | data_writes1, arraysize(data_writes1)); |
| 13675 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13676 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13677 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13678 | |
| 13679 | TestCompletionCallback callback1; |
| 13680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13683 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13685 | |
| 13686 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13687 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13688 | TestNetLogEntry::List entries; |
| 13689 | log.GetEntries(&entries); |
| 13690 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13691 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13692 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13693 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13694 | entries, pos, |
| 13695 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13696 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13698 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13699 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13700 | |
| 13701 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13702 | EXPECT_EQ(200, response->headers->response_code()); |
| 13703 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13704 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13705 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13706 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13707 | HostPortPair::FromString("myproxy:70")), |
| 13708 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13709 | |
| 13710 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13711 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13712 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13713 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13714 | } |
| 13715 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13716 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13717 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13718 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13719 | session_deps_.proxy_resolution_service = |
| 13720 | ProxyResolutionService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13721 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13722 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13724 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13725 | HttpRequestInfo request; |
| 13726 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13727 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13728 | |
| 13729 | // Since we have proxy, should try to establish tunnel. |
| 13730 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13731 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13732 | "Host: www.example.org:443\r\n" |
| 13733 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13734 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13735 | MockWrite("GET / HTTP/1.1\r\n" |
| 13736 | "Host: www.example.org\r\n" |
| 13737 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13738 | }; |
| 13739 | |
| 13740 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13741 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13742 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13743 | }; |
| 13744 | |
| 13745 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13746 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13747 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13748 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13749 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13750 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13751 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13755 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13757 | |
| 13758 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13759 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13760 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13761 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13762 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13763 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13764 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13765 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13766 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13767 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13768 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13769 | } |
| 13770 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13771 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13772 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13773 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13774 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13775 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13776 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13777 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13778 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13779 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13780 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13781 | }; |
| 13782 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13783 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13784 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13785 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13786 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13787 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13788 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13790 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13792 | |
| 13793 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13794 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13795 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 13796 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13797 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13798 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13799 | |
| 13800 | HttpRequestInfo request; |
| 13801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13802 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13803 | |
| 13804 | // This is the important line that marks this as a preconnect. |
| 13805 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13807 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13808 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13809 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13810 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13812 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13813 | } |
| 13814 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13815 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13816 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13817 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13818 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13819 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13820 | request_info.url = GURL("https://www.example.com/"); |
| 13821 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13822 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13823 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13824 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13825 | MockWrite data_writes[] = { |
| 13826 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13827 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13828 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13829 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13833 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13835 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13836 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13837 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13838 | rv = callback.WaitForResult(); |
| 13839 | ASSERT_EQ(error, rv); |
| 13840 | } |
| 13841 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13842 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13843 | // Just check a grab bag of cert errors. |
| 13844 | static const int kErrors[] = { |
| 13845 | ERR_CERT_COMMON_NAME_INVALID, |
| 13846 | ERR_CERT_AUTHORITY_INVALID, |
| 13847 | ERR_CERT_DATE_INVALID, |
| 13848 | }; |
| 13849 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13850 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13851 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13852 | } |
| 13853 | } |
| 13854 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13855 | // Ensure that a client certificate is removed from the SSL client auth |
| 13856 | // cache when: |
| 13857 | // 1) No proxy is involved. |
| 13858 | // 2) TLS False Start is disabled. |
| 13859 | // 3) The initial TLS handshake requests a client certificate. |
| 13860 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13861 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13862 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13863 | request_info.url = GURL("https://www.example.com/"); |
| 13864 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13865 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13866 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13867 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13868 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13869 | |
| 13870 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13871 | // CertificateRequest is received for the first time, the handshake will |
| 13872 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13873 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13874 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13876 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13878 | |
| 13879 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13880 | // False Start is not being used, the result of the SSL handshake will be |
| 13881 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13882 | // matches the result of a server sending a handshake_failure alert, |
| 13883 | // rather than a Finished message, because it requires a client |
| 13884 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13885 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13886 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13887 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13888 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13889 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13890 | |
| 13891 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13892 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13893 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13894 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13895 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13896 | // requiring a client certificate, this fallback handshake should also |
| 13897 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13898 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13899 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13901 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13902 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13903 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13904 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13905 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13906 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13907 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13908 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13909 | // requiring a client certificate, this fallback handshake should also |
| 13910 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13911 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13912 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13914 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13915 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13916 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13919 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13920 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13921 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13922 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13923 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13924 | |
| 13925 | // Complete the SSL handshake, which should abort due to requiring a |
| 13926 | // client certificate. |
| 13927 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13928 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13929 | |
| 13930 | // Indicate that no certificate should be supplied. From the perspective |
| 13931 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13932 | // certificate, so this is the same as supply a |
| 13933 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13934 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13935 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13936 | |
| 13937 | // Ensure the certificate was added to the client auth cache before |
| 13938 | // allowing the connection to continue restarting. |
| 13939 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13940 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13941 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13942 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13943 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13944 | |
| 13945 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13946 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13947 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13949 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13950 | |
| 13951 | // Ensure that the client certificate is removed from the cache on a |
| 13952 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13953 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13954 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13955 | } |
| 13956 | |
| 13957 | // Ensure that a client certificate is removed from the SSL client auth |
| 13958 | // cache when: |
| 13959 | // 1) No proxy is involved. |
| 13960 | // 2) TLS False Start is enabled. |
| 13961 | // 3) The initial TLS handshake requests a client certificate. |
| 13962 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13963 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13964 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13965 | request_info.url = GURL("https://www.example.com/"); |
| 13966 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13967 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13968 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13969 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13970 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13971 | |
| 13972 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13973 | // return successfully after reading up to the peer's Certificate message. |
| 13974 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13975 | // enqueue application data to be sent in the same packet as the |
| 13976 | // ChangeCipherSpec and Finished messages. |
| 13977 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13978 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13979 | // Finished messages. If there was an error negotiating with the peer, |
| 13980 | // such as due to the peer requiring a client certificate when none was |
| 13981 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13982 | // called. |
| 13983 | |
| 13984 | // Like the non-False Start case, when a client certificate is requested by |
| 13985 | // the peer, the handshake is aborted during the Connect() call. |
| 13986 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13987 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13988 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13989 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13990 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13991 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13992 | |
| 13993 | // When a client certificate is supplied, Connect() will not be aborted |
| 13994 | // when the peer requests the certificate. Instead, the handshake will |
| 13995 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13996 | // the socket. The handshake messages are not processed until Read() is |
| 13997 | // called, which then detects that the handshake was aborted, due to the |
| 13998 | // peer sending a handshake_failure because it requires a client |
| 13999 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14000 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14001 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14002 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14003 | MockRead data2_reads[] = { |
| 14004 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14005 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14006 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14007 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14008 | |
| 14009 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14010 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14011 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14012 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14013 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14015 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14016 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14017 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14018 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14019 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14020 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14021 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14022 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14023 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14024 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14025 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14026 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14027 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14028 | ssl_data5.cert_request_info = cert_request.get(); |
| 14029 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14030 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14031 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14035 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14036 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14037 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14038 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14039 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14040 | |
| 14041 | // Complete the SSL handshake, which should abort due to requiring a |
| 14042 | // client certificate. |
| 14043 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14044 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14045 | |
| 14046 | // Indicate that no certificate should be supplied. From the perspective |
| 14047 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14048 | // certificate, so this is the same as supply a |
| 14049 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14050 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14051 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14052 | |
| 14053 | // Ensure the certificate was added to the client auth cache before |
| 14054 | // allowing the connection to continue restarting. |
| 14055 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14056 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14057 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14058 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14059 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14060 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14061 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14062 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14063 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14065 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14066 | |
| 14067 | // Ensure that the client certificate is removed from the cache on a |
| 14068 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14069 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14070 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14071 | } |
| 14072 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14073 | // Ensure that a client certificate is removed from the SSL client auth |
| 14074 | // cache when: |
| 14075 | // 1) An HTTPS proxy is involved. |
| 14076 | // 3) The HTTPS proxy requests a client certificate. |
| 14077 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14078 | // proxy. |
| 14079 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14080 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14081 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14082 | session_deps_.proxy_resolution_service = |
| 14083 | ProxyResolutionService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14084 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14085 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14086 | |
| 14087 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14088 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14089 | |
| 14090 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14091 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14092 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14093 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14094 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14095 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14097 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14098 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14099 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14100 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14101 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14102 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14103 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14104 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14105 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14106 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14107 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14108 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14109 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14110 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14111 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14112 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14113 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14114 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14115 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14116 | requests[0].url = GURL("https://www.example.com/"); |
| 14117 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14118 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14119 | |
| 14120 | requests[1].url = GURL("http://www.example.com/"); |
| 14121 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14122 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14123 | |
| 14124 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14125 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14127 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14128 | |
| 14129 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14130 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14131 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14132 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14133 | |
| 14134 | // Complete the SSL handshake, which should abort due to requiring a |
| 14135 | // client certificate. |
| 14136 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14137 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14138 | |
| 14139 | // Indicate that no certificate should be supplied. From the perspective |
| 14140 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14141 | // certificate, so this is the same as supply a |
| 14142 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14143 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14144 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14145 | |
| 14146 | // Ensure the certificate was added to the client auth cache before |
| 14147 | // allowing the connection to continue restarting. |
| 14148 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14149 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14150 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14151 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14152 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14153 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14154 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14155 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14156 | HostPortPair("www.example.com", 443), &client_cert, |
| 14157 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14158 | |
| 14159 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14160 | // then consume ssl_data3, which should also fail. The result code is |
| 14161 | // checked against what ssl_data3 should return. |
| 14162 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14163 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14164 | |
| 14165 | // Now that the new handshake has failed, ensure that the client |
| 14166 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14167 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14168 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14169 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14170 | HostPortPair("www.example.com", 443), &client_cert, |
| 14171 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14172 | } |
| 14173 | } |
| 14174 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14175 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14176 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14177 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14179 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14180 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14181 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14182 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14183 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14184 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14185 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14186 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14187 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14188 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14189 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14190 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14191 | SpdySerializedFrame host1_resp_body( |
| 14192 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14193 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14194 | SpdySerializedFrame host2_resp_body( |
| 14195 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14196 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14197 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14198 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14199 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14200 | }; |
| 14201 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14202 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14203 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14204 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14205 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14206 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14207 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14208 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14209 | HttpRequestInfo request1; |
| 14210 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14211 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14212 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14213 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14214 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14215 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14217 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14218 | |
| 14219 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14220 | ASSERT_TRUE(response); |
| 14221 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14222 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14223 | |
| 14224 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14225 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14226 | EXPECT_EQ("hello!", response_data); |
| 14227 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14228 | // Preload mail.example.com into HostCache. |
| 14229 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14230 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14231 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14232 | std::unique_ptr<HostResolver::Request> request; |
| 14233 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14234 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14235 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14237 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14238 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14239 | |
| 14240 | HttpRequestInfo request2; |
| 14241 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14242 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14243 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14244 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14245 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14246 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14248 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14249 | |
| 14250 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14251 | ASSERT_TRUE(response); |
| 14252 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14253 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14254 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14255 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14256 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14257 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14258 | } |
| 14259 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14260 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14261 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14262 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14264 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14265 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14266 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14267 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14268 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14269 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14270 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14271 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14272 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14273 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14274 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14275 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14276 | SpdySerializedFrame host1_resp_body( |
| 14277 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14278 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14279 | SpdySerializedFrame host2_resp_body( |
| 14280 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14281 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14282 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14283 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14284 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14285 | }; |
| 14286 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14287 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14288 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14289 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14290 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14291 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14292 | |
| 14293 | TestCompletionCallback callback; |
| 14294 | HttpRequestInfo request1; |
| 14295 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14296 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14297 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14298 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14299 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14300 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14302 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14303 | |
| 14304 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14305 | ASSERT_TRUE(response); |
| 14306 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14307 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14308 | |
| 14309 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14310 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14311 | EXPECT_EQ("hello!", response_data); |
| 14312 | |
| 14313 | HttpRequestInfo request2; |
| 14314 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14315 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14316 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14317 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14318 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14319 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14320 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14321 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14322 | |
| 14323 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14324 | ASSERT_TRUE(response); |
| 14325 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14326 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14327 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14328 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14329 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14330 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14331 | } |
| 14332 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14333 | // Regression test for https://crbug.com/546991. |
| 14334 | // The server might not be able to serve an IP pooled request, and might send a |
| 14335 | // 421 Misdirected Request response status to indicate this. |
| 14336 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14337 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14338 | // Two hosts resolve to the same IP address. |
| 14339 | const std::string ip_addr = "1.2.3.4"; |
| 14340 | IPAddress ip; |
| 14341 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14342 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14343 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14344 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14345 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14346 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14347 | |
| 14348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14349 | |
| 14350 | // Two requests on the first connection. |
| 14351 | SpdySerializedFrame req1( |
| 14352 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14353 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14354 | SpdySerializedFrame req2( |
| 14355 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14356 | SpdySerializedFrame rst( |
| 14357 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14358 | MockWrite writes1[] = { |
| 14359 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14360 | CreateMockWrite(rst, 6), |
| 14361 | }; |
| 14362 | |
| 14363 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14364 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14365 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14366 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14367 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14368 | SpdySerializedFrame resp2( |
| 14369 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14370 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14371 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14372 | |
| 14373 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14374 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14375 | arraysize(writes1)); |
| 14376 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14377 | |
| 14378 | AddSSLSocketData(); |
| 14379 | |
| 14380 | // Retry the second request on a second connection. |
| 14381 | SpdyTestUtil spdy_util2; |
| 14382 | SpdySerializedFrame req3( |
| 14383 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14384 | MockWrite writes2[] = { |
| 14385 | CreateMockWrite(req3, 0), |
| 14386 | }; |
| 14387 | |
| 14388 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14389 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14390 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14391 | MockRead(ASYNC, 0, 3)}; |
| 14392 | |
| 14393 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14394 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14395 | arraysize(writes2)); |
| 14396 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14397 | |
| 14398 | AddSSLSocketData(); |
| 14399 | |
| 14400 | // Preload mail.example.org into HostCache. |
| 14401 | HostPortPair host_port("mail.example.org", 443); |
| 14402 | HostResolver::RequestInfo resolve_info(host_port); |
| 14403 | AddressList ignored; |
| 14404 | std::unique_ptr<HostResolver::Request> request; |
| 14405 | TestCompletionCallback callback; |
| 14406 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14407 | &ignored, callback.callback(), |
| 14408 | &request, NetLogWithSource()); |
| 14409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14410 | rv = callback.WaitForResult(); |
| 14411 | EXPECT_THAT(rv, IsOk()); |
| 14412 | |
| 14413 | HttpRequestInfo request1; |
| 14414 | request1.method = "GET"; |
| 14415 | request1.url = GURL("https://www.example.org/"); |
| 14416 | request1.load_flags = 0; |
| 14417 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14418 | |
| 14419 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14421 | rv = callback.WaitForResult(); |
| 14422 | EXPECT_THAT(rv, IsOk()); |
| 14423 | |
| 14424 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14425 | ASSERT_TRUE(response); |
| 14426 | ASSERT_TRUE(response->headers); |
| 14427 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14428 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14429 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14430 | std::string response_data; |
| 14431 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14432 | EXPECT_EQ("hello!", response_data); |
| 14433 | |
| 14434 | HttpRequestInfo request2; |
| 14435 | request2.method = "GET"; |
| 14436 | request2.url = GURL("https://mail.example.org/"); |
| 14437 | request2.load_flags = 0; |
| 14438 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14439 | |
| 14440 | BoundTestNetLog log; |
| 14441 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14443 | rv = callback.WaitForResult(); |
| 14444 | EXPECT_THAT(rv, IsOk()); |
| 14445 | |
| 14446 | response = trans2.GetResponseInfo(); |
| 14447 | ASSERT_TRUE(response); |
| 14448 | ASSERT_TRUE(response->headers); |
| 14449 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14450 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14451 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14452 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14453 | EXPECT_EQ("hello!", response_data); |
| 14454 | |
| 14455 | TestNetLogEntry::List entries; |
| 14456 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14457 | ExpectLogContainsSomewhere( |
| 14458 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14459 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14460 | } |
| 14461 | |
| 14462 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14463 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14464 | // portions of the response. |
| 14465 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14466 | // Two hosts resolve to the same IP address. |
| 14467 | const std::string ip_addr = "1.2.3.4"; |
| 14468 | IPAddress ip; |
| 14469 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14470 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14471 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14472 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14473 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14474 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14475 | |
| 14476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14477 | |
| 14478 | // Two requests on the first connection. |
| 14479 | SpdySerializedFrame req1( |
| 14480 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14481 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14482 | SpdySerializedFrame req2( |
| 14483 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14484 | SpdySerializedFrame rst( |
| 14485 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14486 | MockWrite writes1[] = { |
| 14487 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14488 | CreateMockWrite(rst, 6), |
| 14489 | }; |
| 14490 | |
| 14491 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14492 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14493 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14494 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14495 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14496 | SpdySerializedFrame resp2( |
| 14497 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14498 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14499 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14500 | |
| 14501 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14502 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14503 | arraysize(writes1)); |
| 14504 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14505 | |
| 14506 | AddSSLSocketData(); |
| 14507 | |
| 14508 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14509 | // Retry again. |
| 14510 | SpdyTestUtil spdy_util2; |
| 14511 | SpdySerializedFrame req3( |
| 14512 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14513 | MockWrite writes2[] = { |
| 14514 | CreateMockWrite(req3, 0), |
| 14515 | }; |
| 14516 | |
| 14517 | SpdySerializedFrame resp3( |
| 14518 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14519 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14520 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14521 | MockRead(ASYNC, 0, 3)}; |
| 14522 | |
| 14523 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14524 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14525 | arraysize(writes2)); |
| 14526 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14527 | |
| 14528 | AddSSLSocketData(); |
| 14529 | |
| 14530 | // Preload mail.example.org into HostCache. |
| 14531 | HostPortPair host_port("mail.example.org", 443); |
| 14532 | HostResolver::RequestInfo resolve_info(host_port); |
| 14533 | AddressList ignored; |
| 14534 | std::unique_ptr<HostResolver::Request> request; |
| 14535 | TestCompletionCallback callback; |
| 14536 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14537 | &ignored, callback.callback(), |
| 14538 | &request, NetLogWithSource()); |
| 14539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14540 | rv = callback.WaitForResult(); |
| 14541 | EXPECT_THAT(rv, IsOk()); |
| 14542 | |
| 14543 | HttpRequestInfo request1; |
| 14544 | request1.method = "GET"; |
| 14545 | request1.url = GURL("https://www.example.org/"); |
| 14546 | request1.load_flags = 0; |
| 14547 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14548 | |
| 14549 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14551 | rv = callback.WaitForResult(); |
| 14552 | EXPECT_THAT(rv, IsOk()); |
| 14553 | |
| 14554 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14555 | ASSERT_TRUE(response); |
| 14556 | ASSERT_TRUE(response->headers); |
| 14557 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14558 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14559 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14560 | std::string response_data; |
| 14561 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14562 | EXPECT_EQ("hello!", response_data); |
| 14563 | |
| 14564 | HttpRequestInfo request2; |
| 14565 | request2.method = "GET"; |
| 14566 | request2.url = GURL("https://mail.example.org/"); |
| 14567 | request2.load_flags = 0; |
| 14568 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14569 | |
| 14570 | BoundTestNetLog log; |
| 14571 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14573 | rv = callback.WaitForResult(); |
| 14574 | EXPECT_THAT(rv, IsOk()); |
| 14575 | |
| 14576 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14577 | // caller. |
| 14578 | response = trans2.GetResponseInfo(); |
| 14579 | ASSERT_TRUE(response); |
| 14580 | ASSERT_TRUE(response->headers); |
| 14581 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14582 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14583 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14584 | EXPECT_TRUE(response->ssl_info.cert); |
| 14585 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14586 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14587 | } |
| 14588 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14589 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14590 | public: |
| 14591 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14592 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14593 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14594 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14595 | int ResolveFromCache(const RequestInfo& info, |
| 14596 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14597 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14598 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14599 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14600 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14601 | return rv; |
| 14602 | } |
| 14603 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14604 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14605 | const HostPortPair host_port_; |
| 14606 | }; |
| 14607 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14608 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14609 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14610 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14611 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14612 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14614 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14615 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14616 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14617 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14618 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14619 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14620 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14621 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14622 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14623 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14624 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14625 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14626 | SpdySerializedFrame host1_resp_body( |
| 14627 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14628 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14629 | SpdySerializedFrame host2_resp_body( |
| 14630 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14631 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14632 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14633 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14634 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14635 | }; |
| 14636 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14637 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14638 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14639 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14640 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14641 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14642 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14643 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14644 | HttpRequestInfo request1; |
| 14645 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14646 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14647 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14648 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14650 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14652 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14653 | |
| 14654 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14655 | ASSERT_TRUE(response); |
| 14656 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14657 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14658 | |
| 14659 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14660 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14661 | EXPECT_EQ("hello!", response_data); |
| 14662 | |
| 14663 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14664 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14665 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14666 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14667 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14668 | &ignored, callback.callback(), |
| 14669 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14671 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14672 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14673 | |
| 14674 | HttpRequestInfo request2; |
| 14675 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14676 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14677 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14678 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14680 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14682 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14683 | |
| 14684 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14685 | ASSERT_TRUE(response); |
| 14686 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14687 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14688 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14689 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14690 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14691 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14692 | } |
| 14693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14694 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14695 | const std::string https_url = "https://www.example.org:8080/"; |
| 14696 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14697 | |
| 14698 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14699 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14700 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14701 | |
| 14702 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14703 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14704 | }; |
| 14705 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14706 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14707 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14708 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14709 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14710 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14711 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14712 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14713 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14714 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14715 | |
| 14716 | // HTTP GET for the HTTP URL |
| 14717 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14718 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14719 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14720 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14721 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14722 | }; |
| 14723 | |
| 14724 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14725 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14726 | MockRead(ASYNC, 2, "hello"), |
| 14727 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14728 | }; |
| 14729 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14730 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14731 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14732 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14733 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14734 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14737 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14738 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14739 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14740 | |
| 14741 | // Start the first transaction to set up the SpdySession |
| 14742 | HttpRequestInfo request1; |
| 14743 | request1.method = "GET"; |
| 14744 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14745 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14746 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14747 | TestCompletionCallback callback1; |
| 14748 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14749 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14750 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14751 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14752 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14753 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14754 | |
| 14755 | // Now, start the HTTP request |
| 14756 | HttpRequestInfo request2; |
| 14757 | request2.method = "GET"; |
| 14758 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14759 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14760 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14761 | TestCompletionCallback callback2; |
| 14762 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14763 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14764 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14765 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14766 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14767 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14768 | } |
| 14769 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14770 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14771 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14772 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14773 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14774 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14775 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14776 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14777 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14778 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14780 | |
| 14781 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14782 | // negotiated. |
| 14783 | StaticSocketDataProvider data; |
| 14784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14785 | |
| 14786 | // 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] | 14787 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14788 | // mocked. This way the request relies on the alternate Job. |
| 14789 | StaticSocketDataProvider data_refused; |
| 14790 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14791 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14792 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14793 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14795 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14796 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14797 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14798 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14799 | http_server_properties->SetHttp2AlternativeService( |
| 14800 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14801 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14802 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14804 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14805 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14806 | TestCompletionCallback callback; |
| 14807 | |
| 14808 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14809 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14810 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14811 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14812 | } |
| 14813 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14814 | // 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] | 14815 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14816 | // succeeds, the request should succeed, even if the latter fails because |
| 14817 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14818 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14819 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14820 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14821 | |
| 14822 | // Negotiate HTTP/1.1 with alternative. |
| 14823 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14824 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14826 | |
| 14827 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14828 | // negotiated. |
| 14829 | StaticSocketDataProvider data; |
| 14830 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14831 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14832 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14833 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14834 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14835 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14836 | |
| 14837 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14838 | MockWrite("GET / HTTP/1.1\r\n" |
| 14839 | "Host: www.example.org\r\n" |
| 14840 | "Connection: keep-alive\r\n\r\n"), |
| 14841 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14842 | "Host: www.example.org\r\n" |
| 14843 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14844 | }; |
| 14845 | |
| 14846 | MockRead http_reads[] = { |
| 14847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14848 | MockRead("Content-Type: text/html\r\n"), |
| 14849 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14850 | MockRead("foobar"), |
| 14851 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14852 | MockRead("Content-Type: text/html\r\n"), |
| 14853 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14854 | MockRead("another"), |
| 14855 | }; |
| 14856 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14857 | http_writes, arraysize(http_writes)); |
| 14858 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14859 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14860 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14862 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14863 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14864 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14865 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14866 | http_server_properties->SetHttp2AlternativeService( |
| 14867 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14868 | |
| 14869 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14870 | HttpRequestInfo request1; |
| 14871 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14872 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14873 | request1.load_flags = 0; |
| 14874 | TestCompletionCallback callback1; |
| 14875 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14876 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14877 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14878 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14879 | |
| 14880 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14881 | ASSERT_TRUE(response1); |
| 14882 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14883 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14884 | |
| 14885 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14886 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14887 | EXPECT_EQ("foobar", response_data1); |
| 14888 | |
| 14889 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14890 | // for alternative service. |
| 14891 | EXPECT_TRUE( |
| 14892 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14893 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14894 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14895 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14896 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14897 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14898 | HttpRequestInfo request2; |
| 14899 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14900 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14901 | request2.load_flags = 0; |
| 14902 | TestCompletionCallback callback2; |
| 14903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14904 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14905 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14906 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14907 | |
| 14908 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14909 | ASSERT_TRUE(response2); |
| 14910 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14911 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14912 | |
| 14913 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14914 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14915 | EXPECT_EQ("another", response_data2); |
| 14916 | } |
| 14917 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14918 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14919 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14920 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14921 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14922 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14923 | HostPortPair alternative("alternative.example.org", 443); |
| 14924 | std::string origin_url = "https://origin.example.org:443"; |
| 14925 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14926 | |
| 14927 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14928 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14929 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14931 | |
| 14932 | // HTTP/1.1 data for |request1| and |request2|. |
| 14933 | MockWrite http_writes[] = { |
| 14934 | MockWrite( |
| 14935 | "GET / HTTP/1.1\r\n" |
| 14936 | "Host: alternative.example.org\r\n" |
| 14937 | "Connection: keep-alive\r\n\r\n"), |
| 14938 | MockWrite( |
| 14939 | "GET / HTTP/1.1\r\n" |
| 14940 | "Host: alternative.example.org\r\n" |
| 14941 | "Connection: keep-alive\r\n\r\n"), |
| 14942 | }; |
| 14943 | |
| 14944 | MockRead http_reads[] = { |
| 14945 | MockRead( |
| 14946 | "HTTP/1.1 200 OK\r\n" |
| 14947 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14948 | "Content-Length: 40\r\n\r\n" |
| 14949 | "first HTTP/1.1 response from alternative"), |
| 14950 | MockRead( |
| 14951 | "HTTP/1.1 200 OK\r\n" |
| 14952 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14953 | "Content-Length: 41\r\n\r\n" |
| 14954 | "second HTTP/1.1 response from alternative"), |
| 14955 | }; |
| 14956 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14957 | http_writes, arraysize(http_writes)); |
| 14958 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14959 | |
| 14960 | // This test documents that an alternate Job should not pool to an already |
| 14961 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14962 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14963 | StaticSocketDataProvider data_refused; |
| 14964 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14965 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14966 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14967 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14969 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14970 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14971 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14972 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14973 | http_server_properties->SetHttp2AlternativeService( |
| 14974 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14975 | |
| 14976 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14977 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14978 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14979 | request1.method = "GET"; |
| 14980 | request1.url = GURL(alternative_url); |
| 14981 | request1.load_flags = 0; |
| 14982 | TestCompletionCallback callback1; |
| 14983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14984 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14985 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14986 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14987 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14988 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14989 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14990 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14991 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14992 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14993 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14994 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14995 | |
| 14996 | // Request for origin.example.org, which has an alternative service. This |
| 14997 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14998 | // 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] | 14999 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15000 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15001 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15002 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15003 | request2.method = "GET"; |
| 15004 | request2.url = GURL(origin_url); |
| 15005 | request2.load_flags = 0; |
| 15006 | TestCompletionCallback callback2; |
| 15007 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15008 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15009 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15010 | |
| 15011 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15012 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15013 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15014 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15015 | request3.method = "GET"; |
| 15016 | request3.url = GURL(alternative_url); |
| 15017 | request3.load_flags = 0; |
| 15018 | TestCompletionCallback callback3; |
| 15019 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15020 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15021 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15022 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15023 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15024 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15025 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15026 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15027 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15028 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15029 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15030 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15031 | } |
| 15032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15033 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15034 | const std::string https_url = "https://www.example.org:8080/"; |
| 15035 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15036 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15037 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15038 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15039 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15040 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15041 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15042 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15043 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15044 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15045 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15046 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15047 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15048 | |
| 15049 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15050 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15051 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15052 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15053 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15054 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15055 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15056 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15057 | |
| 15058 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15059 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15060 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15061 | }; |
| 15062 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15063 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15064 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15065 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15066 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15067 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15068 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15069 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15070 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15071 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15072 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15073 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15074 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15075 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15076 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15077 | CreateMockRead(wrapped_resp1, 4), |
| 15078 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15079 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15080 | CreateMockRead(resp2, 8), |
| 15081 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15082 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15083 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15084 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15085 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15086 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15087 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15088 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15089 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15090 | session_deps_.proxy_resolution_service = |
| 15091 | ProxyResolutionService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15092 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15093 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15094 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15095 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15096 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15097 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15098 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15099 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15100 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15102 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15103 | |
| 15104 | // Start the first transaction to set up the SpdySession |
| 15105 | HttpRequestInfo request1; |
| 15106 | request1.method = "GET"; |
| 15107 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15108 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15109 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15110 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15111 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15112 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15113 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15114 | data1.RunUntilPaused(); |
| 15115 | base::RunLoop().RunUntilIdle(); |
| 15116 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15117 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15118 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15119 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15120 | LoadTimingInfo load_timing_info1; |
| 15121 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15122 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15123 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15124 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15125 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15126 | HttpRequestInfo request2; |
| 15127 | request2.method = "GET"; |
| 15128 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15129 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15130 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15131 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15132 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15133 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15134 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15135 | data1.RunUntilPaused(); |
| 15136 | base::RunLoop().RunUntilIdle(); |
| 15137 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15138 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15139 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15140 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15141 | |
| 15142 | LoadTimingInfo load_timing_info2; |
| 15143 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15144 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15145 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15146 | // HTTP requests over a SPDY session should have a different connection |
| 15147 | // socket_log_id than requests over a tunnel. |
| 15148 | 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] | 15149 | } |
| 15150 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15151 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15152 | // that we do not pool other origins that resolve to the same IP when |
| 15153 | // the certificate does not match the new origin. |
| 15154 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15155 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15156 | const std::string url1 = "http://www.example.org/"; |
| 15157 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15158 | const std::string ip_addr = "1.2.3.4"; |
| 15159 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15160 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15161 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15162 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15163 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15164 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15165 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15166 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15167 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15168 | |
| 15169 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15170 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15171 | }; |
| 15172 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15173 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15174 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15175 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15176 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15177 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15178 | }; |
| 15179 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15180 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15181 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15182 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15183 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15184 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15185 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15186 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15187 | |
| 15188 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15189 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15190 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15191 | |
| 15192 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15193 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15194 | }; |
| 15195 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15196 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15197 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15198 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15199 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15200 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15201 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15202 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15203 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15204 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15205 | |
| 15206 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15207 | // all others direct. |
| 15208 | ProxyConfig proxy_config; |
| 15209 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15210 | session_deps_.proxy_resolution_service = std::make_unique<ProxyResolutionService>( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15211 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15212 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15213 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15214 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15215 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15216 | // Load a valid cert. Note, that this does not need to |
| 15217 | // be valid for proxy because the MockSSLClientSocket does |
| 15218 | // not actually verify it. But SpdySession will use this |
| 15219 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15220 | ssl1.ssl_info.cert = |
| 15221 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15222 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15224 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15225 | |
| 15226 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15227 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15228 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15229 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15230 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15231 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15232 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15233 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15234 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15235 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15236 | |
| 15237 | // Start the first transaction to set up the SpdySession |
| 15238 | HttpRequestInfo request1; |
| 15239 | request1.method = "GET"; |
| 15240 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15241 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15242 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15243 | TestCompletionCallback callback1; |
| 15244 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15245 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15246 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15247 | data1.RunUntilPaused(); |
| 15248 | base::RunLoop().RunUntilIdle(); |
| 15249 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15250 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15251 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15252 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15253 | |
| 15254 | // Now, start the HTTP request |
| 15255 | HttpRequestInfo request2; |
| 15256 | request2.method = "GET"; |
| 15257 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15258 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15259 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15260 | TestCompletionCallback callback2; |
| 15261 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15262 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15263 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15264 | |
| 15265 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15266 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15267 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15268 | } |
| 15269 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15270 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15271 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15272 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15273 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15274 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15275 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15276 | |
| 15277 | MockRead reads1[] = { |
| 15278 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15279 | }; |
| 15280 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15281 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15282 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15283 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15284 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15285 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15286 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15287 | }; |
| 15288 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15289 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15290 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15291 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15292 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15293 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15294 | }; |
| 15295 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15296 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15297 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15298 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15299 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15300 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15302 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15303 | |
| 15304 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15305 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15306 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15307 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15308 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15309 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15310 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15311 | |
| 15312 | // Start the first transaction to set up the SpdySession and verify that |
| 15313 | // connection was closed. |
| 15314 | HttpRequestInfo request1; |
| 15315 | request1.method = "GET"; |
| 15316 | request1.url = GURL(https_url); |
| 15317 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15318 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15319 | TestCompletionCallback callback1; |
| 15320 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15321 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15322 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15323 | |
| 15324 | // Now, start the second request and make sure it succeeds. |
| 15325 | HttpRequestInfo request2; |
| 15326 | request2.method = "GET"; |
| 15327 | request2.url = GURL(https_url); |
| 15328 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15329 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15330 | TestCompletionCallback callback2; |
| 15331 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15332 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15333 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15334 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15335 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15336 | } |
| 15337 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15338 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15339 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15340 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15341 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15342 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15343 | |
| 15344 | // Use two different hosts with different IPs so they don't get pooled. |
| 15345 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15346 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15348 | |
| 15349 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15350 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15351 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15352 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15355 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15356 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15357 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15358 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15359 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15360 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15361 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15362 | SpdySerializedFrame host1_resp_body( |
| 15363 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15364 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15365 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15366 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15367 | }; |
| 15368 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15369 | // Use a separate test instance for the separate SpdySession that will be |
| 15370 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15371 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15372 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15373 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15374 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15375 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15376 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15377 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15378 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15379 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15380 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15381 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15382 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15383 | SpdySerializedFrame host2_resp_body( |
| 15384 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15385 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15386 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15387 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15388 | }; |
| 15389 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15390 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15391 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15392 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15393 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15394 | |
| 15395 | MockWrite http_write[] = { |
| 15396 | MockWrite("GET / HTTP/1.1\r\n" |
| 15397 | "Host: www.a.com\r\n" |
| 15398 | "Connection: keep-alive\r\n\r\n"), |
| 15399 | }; |
| 15400 | |
| 15401 | MockRead http_read[] = { |
| 15402 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15403 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15404 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15405 | MockRead("hello!"), |
| 15406 | }; |
| 15407 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15408 | http_write, arraysize(http_write)); |
| 15409 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15410 | |
| 15411 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15412 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15413 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15414 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15415 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15416 | |
| 15417 | TestCompletionCallback callback; |
| 15418 | HttpRequestInfo request1; |
| 15419 | request1.method = "GET"; |
| 15420 | request1.url = GURL("https://www.a.com/"); |
| 15421 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15422 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15423 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15424 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15425 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15426 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15427 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15428 | |
| 15429 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15430 | ASSERT_TRUE(response); |
| 15431 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15432 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15433 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15434 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15435 | |
| 15436 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15437 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15438 | EXPECT_EQ("hello!", response_data); |
| 15439 | trans.reset(); |
| 15440 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15441 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15442 | |
| 15443 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15444 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15445 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15446 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15447 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15448 | HttpRequestInfo request2; |
| 15449 | request2.method = "GET"; |
| 15450 | request2.url = GURL("https://www.b.com/"); |
| 15451 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15452 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15453 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15455 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15457 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15458 | |
| 15459 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15460 | ASSERT_TRUE(response); |
| 15461 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15462 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15463 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15464 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15465 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15466 | EXPECT_EQ("hello!", response_data); |
| 15467 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15468 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15469 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15470 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15471 | |
| 15472 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15473 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15474 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15475 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15476 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15477 | HttpRequestInfo request3; |
| 15478 | request3.method = "GET"; |
| 15479 | request3.url = GURL("http://www.a.com/"); |
| 15480 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15481 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15482 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15484 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15487 | |
| 15488 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15489 | ASSERT_TRUE(response); |
| 15490 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15491 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15492 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15493 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15494 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15495 | EXPECT_EQ("hello!", response_data); |
| 15496 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15497 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15498 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15499 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15500 | } |
| 15501 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15502 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15503 | HttpRequestInfo request; |
| 15504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15505 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15508 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15509 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15510 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15511 | StaticSocketDataProvider data; |
| 15512 | data.set_connect_data(mock_connect); |
| 15513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15514 | |
| 15515 | TestCompletionCallback callback; |
| 15516 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15517 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15519 | |
| 15520 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15521 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15522 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15523 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15524 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15525 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15526 | |
| 15527 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15528 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15529 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15530 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15531 | |
| 15532 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15533 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15534 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15535 | } |
| 15536 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15537 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15538 | HttpRequestInfo request; |
| 15539 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15540 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15541 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15544 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15545 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15546 | StaticSocketDataProvider data; |
| 15547 | data.set_connect_data(mock_connect); |
| 15548 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15549 | |
| 15550 | TestCompletionCallback callback; |
| 15551 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15552 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15554 | |
| 15555 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15556 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15557 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15558 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15559 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15560 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15561 | |
| 15562 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15563 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15564 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15565 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15566 | |
| 15567 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15568 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15569 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15570 | } |
| 15571 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15572 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15573 | HttpRequestInfo request; |
| 15574 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15575 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15578 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15579 | |
| 15580 | MockWrite data_writes[] = { |
| 15581 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15582 | }; |
| 15583 | MockRead data_reads[] = { |
| 15584 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15585 | }; |
| 15586 | |
| 15587 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15588 | data_writes, arraysize(data_writes)); |
| 15589 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15590 | |
| 15591 | TestCompletionCallback callback; |
| 15592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15593 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15595 | |
| 15596 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15597 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15598 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15599 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15600 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15601 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15602 | } |
| 15603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15604 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15605 | HttpRequestInfo request; |
| 15606 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15607 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15608 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15611 | |
| 15612 | MockWrite data_writes[] = { |
| 15613 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15614 | }; |
| 15615 | MockRead data_reads[] = { |
| 15616 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15617 | }; |
| 15618 | |
| 15619 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15620 | data_writes, arraysize(data_writes)); |
| 15621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15622 | |
| 15623 | TestCompletionCallback callback; |
| 15624 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15625 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15627 | |
| 15628 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15629 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15630 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15631 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15632 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15633 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15634 | } |
| 15635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15636 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15637 | HttpRequestInfo request; |
| 15638 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15639 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15640 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15643 | |
| 15644 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15645 | MockWrite( |
| 15646 | "GET / HTTP/1.1\r\n" |
| 15647 | "Host: www.example.org\r\n" |
| 15648 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15649 | }; |
| 15650 | MockRead data_reads[] = { |
| 15651 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15652 | }; |
| 15653 | |
| 15654 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15655 | data_writes, arraysize(data_writes)); |
| 15656 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15657 | |
| 15658 | TestCompletionCallback callback; |
| 15659 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15660 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15662 | |
| 15663 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15664 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15665 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15666 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15667 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15668 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15669 | } |
| 15670 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15671 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15672 | HttpRequestInfo request; |
| 15673 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15674 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15678 | |
| 15679 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15680 | MockWrite( |
| 15681 | "GET / HTTP/1.1\r\n" |
| 15682 | "Host: www.example.org\r\n" |
| 15683 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15684 | }; |
| 15685 | MockRead data_reads[] = { |
| 15686 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15687 | }; |
| 15688 | |
| 15689 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15690 | data_writes, arraysize(data_writes)); |
| 15691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15692 | |
| 15693 | TestCompletionCallback callback; |
| 15694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15697 | |
| 15698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15699 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15700 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15701 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15702 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15703 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15704 | } |
| 15705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15706 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15707 | HttpRequestInfo request; |
| 15708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15709 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15710 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15713 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15714 | |
| 15715 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15716 | MockWrite( |
| 15717 | "GET / HTTP/1.1\r\n" |
| 15718 | "Host: www.example.org\r\n" |
| 15719 | "Connection: keep-alive\r\n" |
| 15720 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15721 | }; |
| 15722 | MockRead data_reads[] = { |
| 15723 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15724 | "Content-Length: 5\r\n\r\n" |
| 15725 | "hello"), |
| 15726 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15727 | }; |
| 15728 | |
| 15729 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15730 | data_writes, arraysize(data_writes)); |
| 15731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15732 | |
| 15733 | TestCompletionCallback callback; |
| 15734 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15735 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15737 | |
| 15738 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15740 | |
| 15741 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15742 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15743 | std::string foo; |
| 15744 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15745 | EXPECT_EQ("bar", foo); |
| 15746 | } |
| 15747 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15748 | namespace { |
| 15749 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15750 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15751 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15752 | public base::SupportsWeakPtr<FakeStream> { |
| 15753 | public: |
| 15754 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15755 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15756 | |
| 15757 | RequestPriority priority() const { return priority_; } |
| 15758 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15759 | int InitializeStream(const HttpRequestInfo* request_info, |
Steven Valdez | b4ff041 | 2018-01-18 22:39:27 | [diff] [blame] | 15760 | bool can_send_early, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15761 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15762 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15763 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15764 | return ERR_IO_PENDING; |
| 15765 | } |
| 15766 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15767 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15768 | HttpResponseInfo* response, |
| 15769 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15770 | ADD_FAILURE(); |
| 15771 | return ERR_UNEXPECTED; |
| 15772 | } |
| 15773 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15774 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15775 | ADD_FAILURE(); |
| 15776 | return ERR_UNEXPECTED; |
| 15777 | } |
| 15778 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15779 | int ReadResponseBody(IOBuffer* buf, |
| 15780 | int buf_len, |
| 15781 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15782 | ADD_FAILURE(); |
| 15783 | return ERR_UNEXPECTED; |
| 15784 | } |
| 15785 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15786 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15787 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15788 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15789 | ADD_FAILURE(); |
| 15790 | return false; |
| 15791 | } |
| 15792 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15793 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15794 | ADD_FAILURE(); |
| 15795 | return false; |
| 15796 | } |
| 15797 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15798 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15799 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15800 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15801 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15802 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15803 | ADD_FAILURE(); |
| 15804 | return 0; |
| 15805 | } |
| 15806 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15807 | int64_t GetTotalSentBytes() const override { |
| 15808 | ADD_FAILURE(); |
| 15809 | return 0; |
| 15810 | } |
| 15811 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15812 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15813 | ADD_FAILURE(); |
| 15814 | return false; |
| 15815 | } |
| 15816 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15817 | bool GetAlternativeService( |
| 15818 | AlternativeService* alternative_service) const override { |
| 15819 | ADD_FAILURE(); |
| 15820 | return false; |
| 15821 | } |
| 15822 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15823 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15824 | |
| 15825 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15826 | ADD_FAILURE(); |
| 15827 | } |
| 15828 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15829 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15830 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15831 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15832 | TokenBindingType tb_type, |
| 15833 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15834 | ADD_FAILURE(); |
| 15835 | return ERR_NOT_IMPLEMENTED; |
| 15836 | } |
| 15837 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15838 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15839 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15840 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15841 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15842 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15843 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15844 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15845 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15846 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15847 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15848 | private: |
| 15849 | RequestPriority priority_; |
| 15850 | |
| 15851 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15852 | }; |
| 15853 | |
| 15854 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15855 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15856 | class FakeStreamRequest : public HttpStreamRequest, |
| 15857 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15858 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15859 | FakeStreamRequest(RequestPriority priority, |
| 15860 | HttpStreamRequest::Delegate* delegate) |
| 15861 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15862 | delegate_(delegate), |
| 15863 | websocket_stream_create_helper_(NULL) {} |
| 15864 | |
| 15865 | FakeStreamRequest(RequestPriority priority, |
| 15866 | HttpStreamRequest::Delegate* delegate, |
| 15867 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15868 | : priority_(priority), |
| 15869 | delegate_(delegate), |
| 15870 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15871 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15872 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15873 | |
| 15874 | RequestPriority priority() const { return priority_; } |
| 15875 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15876 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15877 | websocket_stream_create_helper() const { |
| 15878 | return websocket_stream_create_helper_; |
| 15879 | } |
| 15880 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15881 | // Create a new FakeStream and pass it to the request's |
| 15882 | // delegate. Returns a weak pointer to the FakeStream. |
| 15883 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15884 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15885 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15886 | // immediately delete |fake_stream|. |
| 15887 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15888 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15889 | return weak_stream; |
| 15890 | } |
| 15891 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15892 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15893 | ADD_FAILURE(); |
| 15894 | return ERR_UNEXPECTED; |
| 15895 | } |
| 15896 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15897 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15898 | ADD_FAILURE(); |
| 15899 | return LoadState(); |
| 15900 | } |
| 15901 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15902 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15903 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15904 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15905 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15906 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15907 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15908 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15909 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15910 | const ConnectionAttempts& connection_attempts() const override { |
| 15911 | static ConnectionAttempts no_attempts; |
| 15912 | return no_attempts; |
| 15913 | } |
| 15914 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15915 | private: |
| 15916 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15917 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15918 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15919 | |
| 15920 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15921 | }; |
| 15922 | |
| 15923 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15924 | class FakeStreamFactory : public HttpStreamFactory { |
| 15925 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15926 | FakeStreamFactory() = default; |
| 15927 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15928 | |
| 15929 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15930 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15931 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15932 | return last_stream_request_; |
| 15933 | } |
| 15934 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15935 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15936 | const HttpRequestInfo& info, |
| 15937 | RequestPriority priority, |
| 15938 | const SSLConfig& server_ssl_config, |
| 15939 | const SSLConfig& proxy_ssl_config, |
| 15940 | HttpStreamRequest::Delegate* delegate, |
| 15941 | bool enable_ip_based_pooling, |
| 15942 | bool enable_alternative_services, |
| 15943 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15944 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15945 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15946 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15947 | } |
| 15948 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15949 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15950 | const HttpRequestInfo& info, |
| 15951 | RequestPriority priority, |
| 15952 | const SSLConfig& server_ssl_config, |
| 15953 | const SSLConfig& proxy_ssl_config, |
| 15954 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15955 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15956 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15957 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15958 | NOTREACHED(); |
| 15959 | return nullptr; |
| 15960 | } |
| 15961 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15962 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15963 | const HttpRequestInfo& info, |
| 15964 | RequestPriority priority, |
| 15965 | const SSLConfig& server_ssl_config, |
| 15966 | const SSLConfig& proxy_ssl_config, |
| 15967 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15968 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15969 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15970 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15971 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15972 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15973 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15974 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15975 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15976 | } |
| 15977 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15978 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15979 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15980 | ADD_FAILURE(); |
| 15981 | } |
| 15982 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15983 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15984 | ADD_FAILURE(); |
| 15985 | return NULL; |
| 15986 | } |
| 15987 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15988 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15989 | const std::string& parent_absolute_name) const override { |
| 15990 | ADD_FAILURE(); |
| 15991 | } |
| 15992 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15993 | private: |
| 15994 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15995 | |
| 15996 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15997 | }; |
| 15998 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15999 | } // namespace |
| 16000 | |
| 16001 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16002 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16003 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16004 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16005 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16006 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16007 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16008 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16009 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16010 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16011 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16012 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16013 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16014 | TestCompletionCallback callback; |
| 16015 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16016 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16017 | |
| 16018 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16019 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16020 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16021 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16022 | } |
| 16023 | |
| 16024 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16025 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16026 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16028 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16029 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16030 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16031 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16032 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16033 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16034 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16035 | TestCompletionCallback callback; |
| 16036 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16037 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16038 | |
| 16039 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16040 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16041 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16042 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16043 | |
| 16044 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16045 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16046 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16047 | } |
| 16048 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16049 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16050 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16051 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16052 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16053 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16054 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16055 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16056 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16057 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16058 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16059 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16060 | TestCompletionCallback callback; |
| 16061 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16062 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16063 | |
| 16064 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16065 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16066 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16067 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16068 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16069 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16070 | |
| 16071 | trans.SetPriority(LOWEST); |
| 16072 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16073 | } |
| 16074 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16075 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16076 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16077 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16078 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16079 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16080 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16081 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16082 | |
| 16083 | // Set up SSL request. |
| 16084 | |
| 16085 | HttpRequestInfo ssl_request; |
| 16086 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16087 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16088 | |
| 16089 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16090 | MockWrite( |
| 16091 | "GET / HTTP/1.1\r\n" |
| 16092 | "Host: www.example.org\r\n" |
| 16093 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16094 | }; |
| 16095 | MockRead ssl_reads[] = { |
| 16096 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16097 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16098 | MockRead("hello world"), |
| 16099 | MockRead(SYNCHRONOUS, OK), |
| 16100 | }; |
| 16101 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16102 | ssl_writes, arraysize(ssl_writes)); |
| 16103 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16104 | |
| 16105 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16107 | |
| 16108 | // Set up HTTP request. |
| 16109 | |
| 16110 | HttpRequestInfo http_request; |
| 16111 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16112 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16113 | |
| 16114 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16115 | MockWrite( |
| 16116 | "GET / HTTP/1.1\r\n" |
| 16117 | "Host: www.example.org\r\n" |
| 16118 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16119 | }; |
| 16120 | MockRead http_reads[] = { |
| 16121 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16122 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16123 | MockRead("falafel"), |
| 16124 | MockRead(SYNCHRONOUS, OK), |
| 16125 | }; |
| 16126 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16127 | http_writes, arraysize(http_writes)); |
| 16128 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16131 | |
| 16132 | // Start the SSL request. |
| 16133 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16134 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16135 | ASSERT_EQ(ERR_IO_PENDING, |
| 16136 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16137 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16138 | |
| 16139 | // Start the HTTP request. Pool should stall. |
| 16140 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16141 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16142 | ASSERT_EQ(ERR_IO_PENDING, |
| 16143 | http_trans.Start(&http_request, http_callback.callback(), |
| 16144 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16145 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16146 | |
| 16147 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16148 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16149 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16150 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16151 | EXPECT_EQ("hello world", response_data); |
| 16152 | |
| 16153 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16154 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16155 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16156 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16157 | |
| 16158 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16159 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16160 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16161 | EXPECT_EQ("falafel", response_data); |
| 16162 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16163 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16164 | } |
| 16165 | |
| 16166 | // Tests that when a SSL connection is established but there's no corresponding |
| 16167 | // request that needs it, the new socket is closed if the transport socket pool |
| 16168 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16169 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16170 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16171 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16172 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16173 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16174 | |
| 16175 | // Set up an ssl request. |
| 16176 | |
| 16177 | HttpRequestInfo ssl_request; |
| 16178 | ssl_request.method = "GET"; |
| 16179 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 16180 | |
| 16181 | // No data will be sent on the SSL socket. |
| 16182 | StaticSocketDataProvider ssl_data; |
| 16183 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16184 | |
| 16185 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16186 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16187 | |
| 16188 | // Set up HTTP request. |
| 16189 | |
| 16190 | HttpRequestInfo http_request; |
| 16191 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16192 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16193 | |
| 16194 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16195 | MockWrite( |
| 16196 | "GET / HTTP/1.1\r\n" |
| 16197 | "Host: www.example.org\r\n" |
| 16198 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16199 | }; |
| 16200 | MockRead http_reads[] = { |
| 16201 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16202 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16203 | MockRead("falafel"), |
| 16204 | MockRead(SYNCHRONOUS, OK), |
| 16205 | }; |
| 16206 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16207 | http_writes, arraysize(http_writes)); |
| 16208 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16209 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16211 | |
| 16212 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16213 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16214 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16215 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16216 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16217 | |
| 16218 | // Start the HTTP request. Pool should stall. |
| 16219 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16220 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16221 | ASSERT_EQ(ERR_IO_PENDING, |
| 16222 | http_trans.Start(&http_request, http_callback.callback(), |
| 16223 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16224 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16225 | |
| 16226 | // The SSL connection will automatically be closed once the connection is |
| 16227 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16228 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16229 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16230 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16231 | EXPECT_EQ("falafel", response_data); |
| 16232 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16233 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16234 | } |
| 16235 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16236 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16237 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16238 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16239 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16240 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16241 | |
| 16242 | HttpRequestInfo request; |
| 16243 | request.method = "POST"; |
| 16244 | request.url = GURL("http://www.foo.com/"); |
| 16245 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16246 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16247 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16249 | // Send headers successfully, but get an error while sending the body. |
| 16250 | MockWrite data_writes[] = { |
| 16251 | MockWrite("POST / HTTP/1.1\r\n" |
| 16252 | "Host: www.foo.com\r\n" |
| 16253 | "Connection: keep-alive\r\n" |
| 16254 | "Content-Length: 3\r\n\r\n"), |
| 16255 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16256 | }; |
| 16257 | |
| 16258 | MockRead data_reads[] = { |
| 16259 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16260 | MockRead("hello world"), |
| 16261 | MockRead(SYNCHRONOUS, OK), |
| 16262 | }; |
| 16263 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16264 | arraysize(data_writes)); |
| 16265 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16266 | |
| 16267 | TestCompletionCallback callback; |
| 16268 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16269 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16271 | |
| 16272 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16273 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16274 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16275 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16276 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16277 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16278 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16279 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16280 | |
| 16281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16282 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16284 | EXPECT_EQ("hello world", response_data); |
| 16285 | } |
| 16286 | |
| 16287 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16288 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16289 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16290 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16292 | MockWrite data_writes[] = { |
| 16293 | MockWrite("GET / HTTP/1.1\r\n" |
| 16294 | "Host: www.foo.com\r\n" |
| 16295 | "Connection: keep-alive\r\n\r\n"), |
| 16296 | MockWrite("POST / HTTP/1.1\r\n" |
| 16297 | "Host: www.foo.com\r\n" |
| 16298 | "Connection: keep-alive\r\n" |
| 16299 | "Content-Length: 3\r\n\r\n"), |
| 16300 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16301 | }; |
| 16302 | |
| 16303 | MockRead data_reads[] = { |
| 16304 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16305 | "Content-Length: 14\r\n\r\n"), |
| 16306 | MockRead("first response"), |
| 16307 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16308 | "Content-Length: 15\r\n\r\n"), |
| 16309 | MockRead("second response"), |
| 16310 | MockRead(SYNCHRONOUS, OK), |
| 16311 | }; |
| 16312 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16313 | arraysize(data_writes)); |
| 16314 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16315 | |
| 16316 | TestCompletionCallback callback; |
| 16317 | HttpRequestInfo request1; |
| 16318 | request1.method = "GET"; |
| 16319 | request1.url = GURL("http://www.foo.com/"); |
| 16320 | request1.load_flags = 0; |
| 16321 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16322 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16323 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16324 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16326 | |
| 16327 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16329 | |
| 16330 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16331 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16332 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16333 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16334 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16335 | |
| 16336 | std::string response_data1; |
| 16337 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16338 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16339 | EXPECT_EQ("first response", response_data1); |
| 16340 | // Delete the transaction to release the socket back into the socket pool. |
| 16341 | trans1.reset(); |
| 16342 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16343 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16344 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16345 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16346 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16347 | |
| 16348 | HttpRequestInfo request2; |
| 16349 | request2.method = "POST"; |
| 16350 | request2.url = GURL("http://www.foo.com/"); |
| 16351 | request2.upload_data_stream = &upload_data_stream; |
| 16352 | request2.load_flags = 0; |
| 16353 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16354 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16355 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16357 | |
| 16358 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16361 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16362 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16363 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16364 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16365 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16366 | |
| 16367 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16368 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16370 | EXPECT_EQ("second response", response_data2); |
| 16371 | } |
| 16372 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16373 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16374 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16375 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16376 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16377 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16378 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16379 | |
| 16380 | HttpRequestInfo request; |
| 16381 | request.method = "POST"; |
| 16382 | request.url = GURL("http://www.foo.com/"); |
| 16383 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16386 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16387 | // Send headers successfully, but get an error while sending the body. |
| 16388 | MockWrite data_writes[] = { |
| 16389 | MockWrite("POST / HTTP/1.1\r\n" |
| 16390 | "Host: www.foo.com\r\n" |
| 16391 | "Connection: keep-alive\r\n" |
| 16392 | "Content-Length: 3\r\n\r\n" |
| 16393 | "fo"), |
| 16394 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16395 | }; |
| 16396 | |
| 16397 | MockRead data_reads[] = { |
| 16398 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16399 | MockRead("hello world"), |
| 16400 | MockRead(SYNCHRONOUS, OK), |
| 16401 | }; |
| 16402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16403 | arraysize(data_writes)); |
| 16404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16405 | |
| 16406 | TestCompletionCallback callback; |
| 16407 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16408 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16410 | |
| 16411 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16414 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16415 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16417 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16418 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16419 | |
| 16420 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16421 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16423 | EXPECT_EQ("hello world", response_data); |
| 16424 | } |
| 16425 | |
| 16426 | // This tests the more common case than the previous test, where headers and |
| 16427 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16428 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16429 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16430 | |
| 16431 | HttpRequestInfo request; |
| 16432 | request.method = "POST"; |
| 16433 | request.url = GURL("http://www.foo.com/"); |
| 16434 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16435 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16438 | // Send headers successfully, but get an error while sending the body. |
| 16439 | MockWrite data_writes[] = { |
| 16440 | MockWrite("POST / HTTP/1.1\r\n" |
| 16441 | "Host: www.foo.com\r\n" |
| 16442 | "Connection: keep-alive\r\n" |
| 16443 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16444 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16445 | }; |
| 16446 | |
| 16447 | MockRead data_reads[] = { |
| 16448 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16449 | MockRead("hello world"), |
| 16450 | MockRead(SYNCHRONOUS, OK), |
| 16451 | }; |
| 16452 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16453 | arraysize(data_writes)); |
| 16454 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16455 | |
| 16456 | TestCompletionCallback callback; |
| 16457 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16458 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16460 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16461 | // they can't be merged with the body in a single send. Not currently |
| 16462 | // necessary since a chunked body is never merged with headers, but this makes |
| 16463 | // the test more future proof. |
| 16464 | base::RunLoop().RunUntilIdle(); |
| 16465 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16466 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16467 | |
| 16468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16471 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16472 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16473 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16474 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16475 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16476 | |
| 16477 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16478 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16479 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16480 | EXPECT_EQ("hello world", response_data); |
| 16481 | } |
| 16482 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16483 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16484 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16485 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16486 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16487 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16488 | |
| 16489 | HttpRequestInfo request; |
| 16490 | request.method = "POST"; |
| 16491 | request.url = GURL("http://www.foo.com/"); |
| 16492 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16493 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16496 | |
| 16497 | MockWrite data_writes[] = { |
| 16498 | MockWrite("POST / HTTP/1.1\r\n" |
| 16499 | "Host: www.foo.com\r\n" |
| 16500 | "Connection: keep-alive\r\n" |
| 16501 | "Content-Length: 3\r\n\r\n"), |
| 16502 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16503 | }; |
| 16504 | |
| 16505 | MockRead data_reads[] = { |
| 16506 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16507 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16508 | MockRead("hello world"), |
| 16509 | MockRead(SYNCHRONOUS, OK), |
| 16510 | }; |
| 16511 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16512 | arraysize(data_writes)); |
| 16513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16514 | |
| 16515 | TestCompletionCallback callback; |
| 16516 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16517 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16519 | |
| 16520 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16521 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16523 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16524 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16525 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16526 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16527 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16528 | |
| 16529 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16530 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16531 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16532 | EXPECT_EQ("hello world", response_data); |
| 16533 | } |
| 16534 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16535 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16536 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16537 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16538 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16539 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16540 | |
| 16541 | HttpRequestInfo request; |
| 16542 | request.method = "POST"; |
| 16543 | request.url = GURL("http://www.foo.com/"); |
| 16544 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16545 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16547 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16548 | // Send headers successfully, but get an error while sending the body. |
| 16549 | MockWrite data_writes[] = { |
| 16550 | MockWrite("POST / HTTP/1.1\r\n" |
| 16551 | "Host: www.foo.com\r\n" |
| 16552 | "Connection: keep-alive\r\n" |
| 16553 | "Content-Length: 3\r\n\r\n"), |
| 16554 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16555 | }; |
| 16556 | |
| 16557 | MockRead data_reads[] = { |
| 16558 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16559 | MockRead("hello world"), |
| 16560 | MockRead(SYNCHRONOUS, OK), |
| 16561 | }; |
| 16562 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16563 | arraysize(data_writes)); |
| 16564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16565 | |
| 16566 | TestCompletionCallback callback; |
| 16567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16568 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16569 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16570 | |
| 16571 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16572 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16573 | } |
| 16574 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16575 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16576 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16577 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16578 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16579 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16580 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16581 | |
| 16582 | HttpRequestInfo request; |
| 16583 | request.method = "POST"; |
| 16584 | request.url = GURL("http://www.foo.com/"); |
| 16585 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16588 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16589 | // Send headers successfully, but get an error while sending the body. |
| 16590 | MockWrite data_writes[] = { |
| 16591 | MockWrite("POST / HTTP/1.1\r\n" |
| 16592 | "Host: www.foo.com\r\n" |
| 16593 | "Connection: keep-alive\r\n" |
| 16594 | "Content-Length: 3\r\n\r\n"), |
| 16595 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16596 | }; |
| 16597 | |
| 16598 | MockRead data_reads[] = { |
| 16599 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16600 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16601 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16602 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16603 | MockRead(SYNCHRONOUS, OK), |
| 16604 | }; |
| 16605 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16606 | arraysize(data_writes)); |
| 16607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16608 | |
| 16609 | TestCompletionCallback callback; |
| 16610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16611 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16613 | |
| 16614 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16615 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16616 | } |
| 16617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16618 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16619 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16620 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16621 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16622 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16623 | |
| 16624 | HttpRequestInfo request; |
| 16625 | request.method = "POST"; |
| 16626 | request.url = GURL("http://www.foo.com/"); |
| 16627 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16628 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16629 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16630 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16631 | // Send headers successfully, but get an error while sending the body. |
| 16632 | MockWrite data_writes[] = { |
| 16633 | MockWrite("POST / HTTP/1.1\r\n" |
| 16634 | "Host: www.foo.com\r\n" |
| 16635 | "Connection: keep-alive\r\n" |
| 16636 | "Content-Length: 3\r\n\r\n"), |
| 16637 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16638 | }; |
| 16639 | |
| 16640 | MockRead data_reads[] = { |
| 16641 | MockRead("HTTP 0.9 rocks!"), |
| 16642 | MockRead(SYNCHRONOUS, OK), |
| 16643 | }; |
| 16644 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16645 | arraysize(data_writes)); |
| 16646 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16647 | |
| 16648 | TestCompletionCallback callback; |
| 16649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16650 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16652 | |
| 16653 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16654 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16655 | } |
| 16656 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16657 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16658 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16659 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16660 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16661 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16662 | |
| 16663 | HttpRequestInfo request; |
| 16664 | request.method = "POST"; |
| 16665 | request.url = GURL("http://www.foo.com/"); |
| 16666 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16667 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16670 | // Send headers successfully, but get an error while sending the body. |
| 16671 | MockWrite data_writes[] = { |
| 16672 | MockWrite("POST / HTTP/1.1\r\n" |
| 16673 | "Host: www.foo.com\r\n" |
| 16674 | "Connection: keep-alive\r\n" |
| 16675 | "Content-Length: 3\r\n\r\n"), |
| 16676 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16677 | }; |
| 16678 | |
| 16679 | MockRead data_reads[] = { |
| 16680 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16681 | MockRead(SYNCHRONOUS, OK), |
| 16682 | }; |
| 16683 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16684 | arraysize(data_writes)); |
| 16685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16686 | |
| 16687 | TestCompletionCallback callback; |
| 16688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16689 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16691 | |
| 16692 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16693 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16694 | } |
| 16695 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16696 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 16697 | |
| 16698 | namespace { |
| 16699 | |
| 16700 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 16701 | headers->SetHeader("Connection", "Upgrade"); |
| 16702 | headers->SetHeader("Upgrade", "websocket"); |
| 16703 | headers->SetHeader("Origin", "http://www.example.org"); |
| 16704 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 16705 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 16706 | } |
| 16707 | |
| 16708 | } // namespace |
| 16709 | |
| 16710 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
| 16711 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 16712 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 16713 | // that the different schemes work. |
| 16714 | std::string test_cases[] = {"ws://www.example.org/", |
| 16715 | "wss://www.example.org/"}; |
| 16716 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
| 16717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16718 | HttpNetworkSessionPeer peer(session.get()); |
| 16719 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 16720 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
| 16721 | |
| 16722 | HttpRequestInfo request; |
| 16723 | request.method = "GET"; |
| 16724 | request.url = GURL(test_cases[i]); |
| 16725 | |
| 16726 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16727 | HttpNetworkTransaction trans(LOW, session.get()); |
| 16728 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 16729 | &websocket_stream_create_helper); |
| 16730 | |
| 16731 | TestCompletionCallback callback; |
| 16732 | EXPECT_EQ(ERR_IO_PENDING, |
| 16733 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 16734 | |
| 16735 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16736 | fake_factory->last_stream_request(); |
| 16737 | ASSERT_TRUE(fake_request); |
| 16738 | EXPECT_EQ(&websocket_stream_create_helper, |
| 16739 | fake_request->websocket_stream_create_helper()); |
| 16740 | } |
| 16741 | } |
| 16742 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16743 | // Verify that proxy headers are not sent to the destination server when |
| 16744 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16745 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16746 | HttpRequestInfo request; |
| 16747 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16748 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16749 | AddWebSocketHeaders(&request.extra_headers); |
| 16750 | |
| 16751 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16752 | session_deps_.proxy_resolution_service = |
| 16753 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16754 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16756 | |
| 16757 | // Since a proxy is configured, try to establish a tunnel. |
| 16758 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16759 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16760 | "Host: www.example.org:443\r\n" |
| 16761 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16762 | |
| 16763 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16764 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16765 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16766 | "Host: www.example.org:443\r\n" |
| 16767 | "Proxy-Connection: keep-alive\r\n" |
| 16768 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16769 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16770 | MockWrite("GET / HTTP/1.1\r\n" |
| 16771 | "Host: www.example.org\r\n" |
| 16772 | "Connection: Upgrade\r\n" |
| 16773 | "Upgrade: websocket\r\n" |
| 16774 | "Origin: http://www.example.org\r\n" |
| 16775 | "Sec-WebSocket-Version: 13\r\n" |
| 16776 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16777 | }; |
| 16778 | |
| 16779 | // The proxy responds to the connect with a 407, using a persistent |
| 16780 | // connection. |
| 16781 | MockRead data_reads[] = { |
| 16782 | // No credentials. |
| 16783 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16784 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16785 | MockRead("Content-Length: 0\r\n"), |
| 16786 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16787 | |
| 16788 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16789 | |
| 16790 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16791 | MockRead("Upgrade: websocket\r\n"), |
| 16792 | MockRead("Connection: Upgrade\r\n"), |
| 16793 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16794 | }; |
| 16795 | |
| 16796 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16797 | arraysize(data_writes)); |
| 16798 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16799 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16801 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16802 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16803 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16804 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16805 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16806 | &websocket_stream_create_helper); |
| 16807 | |
| 16808 | { |
| 16809 | TestCompletionCallback callback; |
| 16810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16811 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16813 | |
| 16814 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16815 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16816 | } |
| 16817 | |
| 16818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16819 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16820 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16821 | EXPECT_EQ(407, response->headers->response_code()); |
| 16822 | |
| 16823 | { |
| 16824 | TestCompletionCallback callback; |
| 16825 | |
| 16826 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16827 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16829 | |
| 16830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16831 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16832 | } |
| 16833 | |
| 16834 | response = trans->GetResponseInfo(); |
| 16835 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16836 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16837 | |
| 16838 | EXPECT_EQ(101, response->headers->response_code()); |
| 16839 | |
| 16840 | trans.reset(); |
| 16841 | session->CloseAllConnections(); |
| 16842 | } |
| 16843 | |
| 16844 | // Verify that proxy headers are not sent to the destination server when |
| 16845 | // establishing a tunnel for an insecure WebSocket connection. |
| 16846 | // This requires the authentication info to be injected into the auth cache |
| 16847 | // due to crbug.com/395064 |
| 16848 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16849 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16850 | HttpRequestInfo request; |
| 16851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16852 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16853 | AddWebSocketHeaders(&request.extra_headers); |
| 16854 | |
| 16855 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16856 | session_deps_.proxy_resolution_service = |
| 16857 | ProxyResolutionService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16860 | |
| 16861 | MockWrite data_writes[] = { |
| 16862 | // Try to establish a tunnel for the WebSocket connection, with |
| 16863 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16864 | // they cannot and will not use the same TCP/IP connection as the |
| 16865 | // preflight HTTP request. |
| 16866 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16867 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16868 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16869 | "Proxy-Connection: keep-alive\r\n" |
| 16870 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16871 | |
| 16872 | MockWrite( |
| 16873 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16874 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16875 | "Connection: Upgrade\r\n" |
| 16876 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16877 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16878 | "Sec-WebSocket-Version: 13\r\n" |
| 16879 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16880 | }; |
| 16881 | |
| 16882 | MockRead data_reads[] = { |
| 16883 | // HTTP CONNECT with credentials. |
| 16884 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16885 | |
| 16886 | // WebSocket connection established inside tunnel. |
| 16887 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16888 | MockRead("Upgrade: websocket\r\n"), |
| 16889 | MockRead("Connection: Upgrade\r\n"), |
| 16890 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16891 | }; |
| 16892 | |
| 16893 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16894 | arraysize(data_writes)); |
| 16895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16896 | |
| 16897 | session->http_auth_cache()->Add( |
| 16898 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16899 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16900 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16901 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16902 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16903 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16904 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16905 | &websocket_stream_create_helper); |
| 16906 | |
| 16907 | TestCompletionCallback callback; |
| 16908 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16909 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16911 | |
| 16912 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16913 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16914 | |
| 16915 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16916 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16917 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16918 | |
| 16919 | EXPECT_EQ(101, response->headers->response_code()); |
| 16920 | |
| 16921 | trans.reset(); |
| 16922 | session->CloseAllConnections(); |
| 16923 | } |
| 16924 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16925 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 16926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16927 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16928 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16929 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16930 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16931 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16932 | |
| 16933 | HttpRequestInfo request; |
| 16934 | request.method = "POST"; |
| 16935 | request.url = GURL("http://www.foo.com/"); |
| 16936 | request.upload_data_stream = &upload_data_stream; |
| 16937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16940 | MockWrite data_writes[] = { |
| 16941 | MockWrite("POST / HTTP/1.1\r\n" |
| 16942 | "Host: www.foo.com\r\n" |
| 16943 | "Connection: keep-alive\r\n" |
| 16944 | "Content-Length: 3\r\n\r\n"), |
| 16945 | MockWrite("foo"), |
| 16946 | }; |
| 16947 | |
| 16948 | MockRead data_reads[] = { |
| 16949 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16950 | MockRead(SYNCHRONOUS, OK), |
| 16951 | }; |
| 16952 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16953 | arraysize(data_writes)); |
| 16954 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16955 | |
| 16956 | TestCompletionCallback callback; |
| 16957 | |
| 16958 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16959 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16960 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16961 | |
| 16962 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16963 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16964 | |
| 16965 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16966 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16967 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16968 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16969 | } |
| 16970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16971 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16972 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16973 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16974 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16975 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16976 | |
| 16977 | HttpRequestInfo request; |
| 16978 | request.method = "POST"; |
| 16979 | request.url = GURL("http://www.foo.com/"); |
| 16980 | request.upload_data_stream = &upload_data_stream; |
| 16981 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16984 | MockWrite data_writes[] = { |
| 16985 | MockWrite("POST / HTTP/1.1\r\n" |
| 16986 | "Host: www.foo.com\r\n" |
| 16987 | "Connection: keep-alive\r\n" |
| 16988 | "Content-Length: 3\r\n\r\n"), |
| 16989 | MockWrite("foo"), |
| 16990 | }; |
| 16991 | |
| 16992 | MockRead data_reads[] = { |
| 16993 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16994 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16995 | MockRead(SYNCHRONOUS, OK), |
| 16996 | }; |
| 16997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16998 | arraysize(data_writes)); |
| 16999 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17000 | |
| 17001 | TestCompletionCallback callback; |
| 17002 | |
| 17003 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17004 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17005 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17006 | |
| 17007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17008 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17009 | |
| 17010 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17011 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17012 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17013 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17014 | } |
| 17015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17016 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17017 | ChunkedUploadDataStream upload_data_stream(0); |
| 17018 | |
| 17019 | HttpRequestInfo request; |
| 17020 | request.method = "POST"; |
| 17021 | request.url = GURL("http://www.foo.com/"); |
| 17022 | request.upload_data_stream = &upload_data_stream; |
| 17023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17025 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17026 | // Send headers successfully, but get an error while sending the body. |
| 17027 | MockWrite data_writes[] = { |
| 17028 | MockWrite("POST / HTTP/1.1\r\n" |
| 17029 | "Host: www.foo.com\r\n" |
| 17030 | "Connection: keep-alive\r\n" |
| 17031 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17032 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17033 | }; |
| 17034 | |
| 17035 | MockRead data_reads[] = { |
| 17036 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17037 | MockRead(SYNCHRONOUS, OK), |
| 17038 | }; |
| 17039 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17040 | arraysize(data_writes)); |
| 17041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17042 | |
| 17043 | TestCompletionCallback callback; |
| 17044 | |
| 17045 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17046 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17047 | |
| 17048 | base::RunLoop().RunUntilIdle(); |
| 17049 | upload_data_stream.AppendData("f", 1, false); |
| 17050 | |
| 17051 | base::RunLoop().RunUntilIdle(); |
| 17052 | upload_data_stream.AppendData("oo", 2, true); |
| 17053 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17054 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17055 | |
| 17056 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17057 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17058 | |
| 17059 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17060 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17061 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17062 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17063 | } |
| 17064 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17065 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17066 | // the unthrottled state are not blocked. |
| 17067 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17068 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17069 | std::unique_ptr<HttpNetworkSession> session( |
| 17070 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17071 | |
| 17072 | // Send a simple request and make sure it goes through. |
| 17073 | HttpRequestInfo request; |
| 17074 | request.method = "GET"; |
| 17075 | request.url = GURL("http://www.example.org/"); |
| 17076 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17077 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17078 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17079 | |
| 17080 | MockWrite data_writes[] = { |
| 17081 | MockWrite("GET / HTTP/1.1\r\n" |
| 17082 | "Host: www.example.org\r\n" |
| 17083 | "Connection: keep-alive\r\n\r\n"), |
| 17084 | }; |
| 17085 | MockRead data_reads[] = { |
| 17086 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17087 | MockRead(SYNCHRONOUS, OK), |
| 17088 | }; |
| 17089 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17090 | arraysize(data_writes)); |
| 17091 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17092 | |
| 17093 | TestCompletionCallback callback; |
| 17094 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17095 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17096 | } |
| 17097 | |
| 17098 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17099 | // when the throttle is unblocked. |
| 17100 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17101 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17102 | std::unique_ptr<HttpNetworkSession> session( |
| 17103 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17104 | |
| 17105 | // Send a simple request and make sure it goes through. |
| 17106 | HttpRequestInfo request; |
| 17107 | request.method = "GET"; |
| 17108 | request.url = GURL("http://www.example.org/"); |
| 17109 | |
| 17110 | MockWrite data_writes[] = { |
| 17111 | MockWrite("GET / HTTP/1.1\r\n" |
| 17112 | "Host: www.example.org\r\n" |
| 17113 | "Connection: keep-alive\r\n\r\n"), |
| 17114 | }; |
| 17115 | MockRead data_reads[] = { |
| 17116 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17117 | MockRead(SYNCHRONOUS, OK), |
| 17118 | }; |
| 17119 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17120 | arraysize(data_writes)); |
| 17121 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17122 | |
| 17123 | // Start a request that will be throttled at start; confirm it |
| 17124 | // doesn't complete. |
| 17125 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17126 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17127 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17128 | |
| 17129 | TestCompletionCallback callback; |
| 17130 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17131 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17132 | |
| 17133 | base::RunLoop().RunUntilIdle(); |
| 17134 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17135 | EXPECT_FALSE(callback.have_result()); |
| 17136 | |
| 17137 | // Confirm the request goes on to complete when unthrottled. |
| 17138 | throttler->UnthrottleAllRequests(); |
| 17139 | base::RunLoop().RunUntilIdle(); |
| 17140 | ASSERT_TRUE(callback.have_result()); |
| 17141 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17142 | } |
| 17143 | |
| 17144 | // Destroy a request while it's throttled. |
| 17145 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17146 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17147 | std::unique_ptr<HttpNetworkSession> session( |
| 17148 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17149 | |
| 17150 | // Send a simple request and make sure it goes through. |
| 17151 | HttpRequestInfo request; |
| 17152 | request.method = "GET"; |
| 17153 | request.url = GURL("http://www.example.org/"); |
| 17154 | |
| 17155 | MockWrite data_writes[] = { |
| 17156 | MockWrite("GET / HTTP/1.1\r\n" |
| 17157 | "Host: www.example.org\r\n" |
| 17158 | "Connection: keep-alive\r\n\r\n"), |
| 17159 | }; |
| 17160 | MockRead data_reads[] = { |
| 17161 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17162 | MockRead(SYNCHRONOUS, OK), |
| 17163 | }; |
| 17164 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17165 | arraysize(data_writes)); |
| 17166 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17167 | |
| 17168 | // Start a request that will be throttled at start; confirm it |
| 17169 | // doesn't complete. |
| 17170 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17171 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17172 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17173 | |
| 17174 | TestCompletionCallback callback; |
| 17175 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17176 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17177 | |
| 17178 | base::RunLoop().RunUntilIdle(); |
| 17179 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17180 | EXPECT_FALSE(callback.have_result()); |
| 17181 | |
| 17182 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17183 | trans.reset(); |
| 17184 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17185 | } |
| 17186 | |
| 17187 | // Confirm the throttler receives SetPriority calls. |
| 17188 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17189 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17190 | std::unique_ptr<HttpNetworkSession> session( |
| 17191 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17192 | |
| 17193 | // Send a simple request and make sure it goes through. |
| 17194 | HttpRequestInfo request; |
| 17195 | request.method = "GET"; |
| 17196 | request.url = GURL("http://www.example.org/"); |
| 17197 | |
| 17198 | MockWrite data_writes[] = { |
| 17199 | MockWrite("GET / HTTP/1.1\r\n" |
| 17200 | "Host: www.example.org\r\n" |
| 17201 | "Connection: keep-alive\r\n\r\n"), |
| 17202 | }; |
| 17203 | MockRead data_reads[] = { |
| 17204 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17205 | MockRead(SYNCHRONOUS, OK), |
| 17206 | }; |
| 17207 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17208 | arraysize(data_writes)); |
| 17209 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17210 | |
| 17211 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17212 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17213 | // Start the transaction to associate a throttle with it. |
| 17214 | TestCompletionCallback callback; |
| 17215 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17216 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17217 | |
| 17218 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17219 | trans->SetPriority(LOW); |
| 17220 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17221 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17222 | |
| 17223 | throttler->UnthrottleAllRequests(); |
| 17224 | base::RunLoop().RunUntilIdle(); |
| 17225 | ASSERT_TRUE(callback.have_result()); |
| 17226 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17227 | } |
| 17228 | |
| 17229 | // Confirm that unthrottling from a SetPriority call by the |
| 17230 | // throttler works properly. |
| 17231 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17232 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17233 | std::unique_ptr<HttpNetworkSession> session( |
| 17234 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17235 | |
| 17236 | // Send a simple request and make sure it goes through. |
| 17237 | HttpRequestInfo request; |
| 17238 | request.method = "GET"; |
| 17239 | request.url = GURL("http://www.example.org/"); |
| 17240 | |
| 17241 | MockWrite data_writes[] = { |
| 17242 | MockWrite("GET / HTTP/1.1\r\n" |
| 17243 | "Host: www.example.org\r\n" |
| 17244 | "Connection: keep-alive\r\n\r\n"), |
| 17245 | }; |
| 17246 | MockRead data_reads[] = { |
| 17247 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17248 | MockRead(SYNCHRONOUS, OK), |
| 17249 | }; |
| 17250 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17251 | arraysize(data_writes)); |
| 17252 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17253 | |
| 17254 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17255 | data_writes, arraysize(data_writes)); |
| 17256 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17257 | |
| 17258 | // Start a request that will be throttled at start; confirm it |
| 17259 | // doesn't complete. |
| 17260 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17261 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17262 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17263 | |
| 17264 | TestCompletionCallback callback; |
| 17265 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17266 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17267 | |
| 17268 | base::RunLoop().RunUntilIdle(); |
| 17269 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17270 | EXPECT_FALSE(callback.have_result()); |
| 17271 | |
| 17272 | // Create a new request, call SetPriority on it to unthrottle, |
| 17273 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17274 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17275 | throttler->set_priority_change_closure( |
| 17276 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17277 | base::Unretained(throttler))); |
| 17278 | |
| 17279 | // Start the transaction to associate a throttle with it. |
| 17280 | TestCompletionCallback callback1; |
| 17281 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17282 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17283 | |
| 17284 | trans1->SetPriority(IDLE); |
| 17285 | |
| 17286 | base::RunLoop().RunUntilIdle(); |
| 17287 | ASSERT_TRUE(callback.have_result()); |
| 17288 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17289 | ASSERT_TRUE(callback1.have_result()); |
| 17290 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17291 | } |
| 17292 | |
| 17293 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17294 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17295 | |
| 17296 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17297 | // throttler works properly. |
| 17298 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17299 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17300 | std::unique_ptr<HttpNetworkSession> session( |
| 17301 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17302 | |
| 17303 | // Send a simple request and make sure it goes through. |
| 17304 | HttpRequestInfo request; |
| 17305 | request.method = "GET"; |
| 17306 | request.url = GURL("http://www.example.org/"); |
| 17307 | |
| 17308 | MockWrite data_writes[] = { |
| 17309 | MockWrite("GET / HTTP/1.1\r\n" |
| 17310 | "Host: www.example.org\r\n" |
| 17311 | "Connection: keep-alive\r\n\r\n"), |
| 17312 | }; |
| 17313 | MockRead data_reads[] = { |
| 17314 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17315 | MockRead(SYNCHRONOUS, OK), |
| 17316 | }; |
| 17317 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17318 | arraysize(data_writes)); |
| 17319 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17320 | |
| 17321 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17322 | data_writes, arraysize(data_writes)); |
| 17323 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17324 | |
| 17325 | // Start a request that will be throttled at start; confirm it |
| 17326 | // doesn't complete. |
| 17327 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17328 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17330 | |
| 17331 | TestCompletionCallback callback; |
| 17332 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17333 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17334 | |
| 17335 | base::RunLoop().RunUntilIdle(); |
| 17336 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17337 | EXPECT_FALSE(callback.have_result()); |
| 17338 | |
| 17339 | // Arrange for the set priority call on the above transaction to delete |
| 17340 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17341 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17342 | throttler->set_priority_change_closure( |
| 17343 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17344 | |
| 17345 | // Call it and check results (partially a "doesn't crash" test). |
| 17346 | trans_ptr->SetPriority(IDLE); |
| 17347 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17348 | |
| 17349 | base::RunLoop().RunUntilIdle(); |
| 17350 | ASSERT_FALSE(callback.have_result()); |
| 17351 | } |
| 17352 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17353 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17354 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17355 | const std::string https_url = "https://www.example.com"; |
| 17356 | HttpRequestInfo request; |
| 17357 | request.url = GURL(https_url); |
| 17358 | request.method = "GET"; |
| 17359 | |
| 17360 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17361 | ssl.ssl_info.token_binding_negotiated = true; |
| 17362 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17363 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17365 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17366 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17367 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17368 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17369 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17370 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17372 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17373 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17375 | |
| 17376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17377 | TestCompletionCallback callback; |
| 17378 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17379 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17380 | |
| 17381 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17382 | |
| 17383 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17384 | HttpRequestHeaders headers; |
| 17385 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17386 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17387 | } |
| 17388 | #endif // !defined(OS_IOS) |
| 17389 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17390 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17391 | const std::string& accept_encoding, |
| 17392 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17393 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17394 | bool should_match) { |
| 17395 | HttpRequestInfo request; |
| 17396 | request.method = "GET"; |
| 17397 | request.url = GURL("http://www.foo.com/"); |
| 17398 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17399 | accept_encoding); |
| 17400 | |
| 17401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17402 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17403 | // Send headers successfully, but get an error while sending the body. |
| 17404 | MockWrite data_writes[] = { |
| 17405 | MockWrite("GET / HTTP/1.1\r\n" |
| 17406 | "Host: www.foo.com\r\n" |
| 17407 | "Connection: keep-alive\r\n" |
| 17408 | "Accept-Encoding: "), |
| 17409 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17410 | }; |
| 17411 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17412 | std::string response_code = "200 OK"; |
| 17413 | std::string extra; |
| 17414 | if (!location.empty()) { |
| 17415 | response_code = "301 Redirect\r\nLocation: "; |
| 17416 | response_code.append(location); |
| 17417 | } |
| 17418 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17419 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17420 | MockRead("HTTP/1.0 "), |
| 17421 | MockRead(response_code.data()), |
| 17422 | MockRead("\r\nContent-Encoding: "), |
| 17423 | MockRead(content_encoding.data()), |
| 17424 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17425 | MockRead(SYNCHRONOUS, OK), |
| 17426 | }; |
| 17427 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17428 | arraysize(data_writes)); |
| 17429 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17430 | |
| 17431 | TestCompletionCallback callback; |
| 17432 | |
| 17433 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17435 | |
| 17436 | rv = callback.WaitForResult(); |
| 17437 | if (should_match) { |
| 17438 | EXPECT_THAT(rv, IsOk()); |
| 17439 | } else { |
| 17440 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17441 | } |
| 17442 | } |
| 17443 | |
| 17444 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17445 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17446 | } |
| 17447 | |
| 17448 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17449 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17450 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17451 | } |
| 17452 | |
| 17453 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17454 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17455 | "", false); |
| 17456 | } |
| 17457 | |
| 17458 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17459 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17460 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17461 | } |
| 17462 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17463 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17464 | ProxyConfig proxy_config; |
| 17465 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17466 | proxy_config.set_pac_mandatory(true); |
| 17467 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17468 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17469 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17470 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17471 | |
| 17472 | HttpRequestInfo request; |
| 17473 | request.method = "GET"; |
| 17474 | request.url = GURL("http://www.example.org/"); |
| 17475 | |
| 17476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17477 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17478 | |
| 17479 | TestCompletionCallback callback; |
| 17480 | |
| 17481 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17483 | EXPECT_THAT(callback.WaitForResult(), |
| 17484 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17485 | } |
| 17486 | |
| 17487 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17488 | ProxyConfig proxy_config; |
| 17489 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17490 | proxy_config.set_pac_mandatory(true); |
| 17491 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17492 | new MockAsyncProxyResolverFactory(false); |
| 17493 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17494 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
| 17495 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 17496 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17497 | HttpRequestInfo request; |
| 17498 | request.method = "GET"; |
| 17499 | request.url = GURL("http://www.example.org/"); |
| 17500 | |
| 17501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17503 | |
| 17504 | TestCompletionCallback callback; |
| 17505 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17507 | |
| 17508 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17509 | ERR_FAILED, &resolver); |
| 17510 | EXPECT_THAT(callback.WaitForResult(), |
| 17511 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17512 | } |
| 17513 | |
| 17514 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17515 | session_deps_.proxy_resolution_service = |
| 17516 | ProxyResolutionService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17517 | session_deps_.enable_quic = false; |
| 17518 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17519 | |
| 17520 | HttpRequestInfo request; |
| 17521 | request.method = "GET"; |
| 17522 | request.url = GURL("http://www.example.org/"); |
| 17523 | |
| 17524 | TestCompletionCallback callback; |
| 17525 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17526 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17527 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17528 | |
| 17529 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17530 | } |
| 17531 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17532 | } // namespace net |