[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" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 45 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 46 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 47 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 48 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 49 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 53 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_basic_state.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" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 63 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 64 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 65 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 66 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 67 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 68 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 69 | #include "net/log/test_net_log_entry.h" |
| 70 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 71 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 72 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 73 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 74 | #include "net/proxy/proxy_resolver.h" |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 75 | #include "net/proxy/proxy_resolver_factory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 76 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 77 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/socket_test_util.h" |
| 85 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 86 | #include "net/spdy/chromium/spdy_session.h" |
| 87 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 88 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 89 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service_defaults.h" |
| 94 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 95 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 96 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 97 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 98 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 99 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 100 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 101 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 102 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 103 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 104 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 106 | #if defined(NTLM_PORTABLE) |
| 107 | #include "base/base64.h" |
| 108 | #include "net/ntlm/ntlm_test_data.h" |
| 109 | #endif |
| 110 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 111 | using net::test::IsError; |
| 112 | using net::test::IsOk; |
| 113 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 114 | using base::ASCIIToUTF16; |
| 115 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 116 | //----------------------------------------------------------------------------- |
| 117 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 118 | namespace net { |
| 119 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 120 | namespace { |
| 121 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 122 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 123 | public: |
| 124 | TestNetworkStreamThrottler() |
| 125 | : throttle_new_requests_(false), |
| 126 | num_set_priority_calls_(0), |
| 127 | last_priority_set_(IDLE) {} |
| 128 | |
| 129 | ~TestNetworkStreamThrottler() override { |
| 130 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 131 | } |
| 132 | |
| 133 | // NetworkThrottleManager |
| 134 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 135 | RequestPriority priority, |
| 136 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 137 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 138 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 139 | outstanding_throttles_.insert(test_throttle.get()); |
| 140 | return std::move(test_throttle); |
| 141 | } |
| 142 | |
| 143 | void UnthrottleAllRequests() { |
| 144 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 145 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 146 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 147 | throttle->Unthrottle(); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 152 | throttle_new_requests_ = throttle_new_requests; |
| 153 | } |
| 154 | |
| 155 | // Includes both throttled and unthrottled throttles. |
| 156 | size_t num_outstanding_requests() const { |
| 157 | return outstanding_throttles_.size(); |
| 158 | } |
| 159 | |
| 160 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 161 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 162 | void set_priority_change_closure( |
| 163 | const base::Closure& priority_change_closure) { |
| 164 | priority_change_closure_ = priority_change_closure; |
| 165 | } |
| 166 | |
| 167 | private: |
| 168 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 169 | public: |
| 170 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 171 | |
| 172 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 173 | bool IsBlocked() const override { return throttled_; } |
| 174 | RequestPriority Priority() const override { |
| 175 | NOTREACHED(); |
| 176 | return IDLE; |
| 177 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 178 | void SetPriority(RequestPriority priority) override { |
| 179 | throttler_->SetPriorityCalled(priority); |
| 180 | } |
| 181 | |
| 182 | TestThrottle(bool throttled, |
| 183 | ThrottleDelegate* delegate, |
| 184 | TestNetworkStreamThrottler* throttler) |
| 185 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 186 | |
| 187 | void Unthrottle() { |
| 188 | EXPECT_TRUE(throttled_); |
| 189 | |
| 190 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 191 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | bool throttled_; |
| 195 | ThrottleDelegate* delegate_; |
| 196 | TestNetworkStreamThrottler* throttler_; |
| 197 | }; |
| 198 | |
| 199 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 200 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 201 | outstanding_throttles_.erase(throttle); |
| 202 | } |
| 203 | |
| 204 | void SetPriorityCalled(RequestPriority priority) { |
| 205 | ++num_set_priority_calls_; |
| 206 | last_priority_set_ = priority; |
| 207 | if (!priority_change_closure_.is_null()) |
| 208 | priority_change_closure_.Run(); |
| 209 | } |
| 210 | |
| 211 | // Includes both throttled and unthrottled throttles. |
| 212 | std::set<TestThrottle*> outstanding_throttles_; |
| 213 | bool throttle_new_requests_; |
| 214 | int num_set_priority_calls_; |
| 215 | RequestPriority last_priority_set_; |
| 216 | base::Closure priority_change_closure_; |
| 217 | |
| 218 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 219 | }; |
| 220 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 221 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 222 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 223 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 224 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 225 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 226 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 227 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 228 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 229 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 230 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 231 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 232 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 233 | const char kAlternativeServiceHttpHeader[] = |
| 234 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 235 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 236 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 237 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 238 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 239 | } |
| 240 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 241 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 242 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 243 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 244 | } |
| 245 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 246 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 247 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 248 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 249 | } |
| 250 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 251 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 252 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 253 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 254 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 255 | if (!params) |
| 256 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 257 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 258 | if (!params->GetList("headers", &header_list)) |
| 259 | return false; |
| 260 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 261 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 262 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 263 | return true; |
| 264 | } |
| 265 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 266 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 267 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 268 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 270 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 271 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 273 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 274 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 275 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 276 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 277 | |
| 278 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 279 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 280 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 281 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 282 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 283 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 286 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 287 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 288 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 289 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 290 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 291 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 292 | |
| 293 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 294 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 295 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 296 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 297 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 298 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 299 | load_timing_info.send_start); |
| 300 | |
| 301 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 302 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 303 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 304 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 305 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 306 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 310 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 311 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 312 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 313 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 314 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 315 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 316 | |
| 317 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 318 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 319 | load_timing_info.proxy_resolve_end); |
| 320 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 321 | load_timing_info.send_start); |
| 322 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 323 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 324 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 325 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 326 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 327 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 331 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 332 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 333 | int connect_timing_flags) { |
| 334 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 335 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 336 | |
| 337 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 338 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 339 | load_timing_info.proxy_resolve_end); |
| 340 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 341 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 342 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 343 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 344 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 345 | load_timing_info.send_start); |
| 346 | |
| 347 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 348 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 349 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 350 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 351 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 352 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 353 | } |
| 354 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 355 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 356 | headers->SetHeader("Connection", "Upgrade"); |
| 357 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 358 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 359 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 360 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 361 | } |
| 362 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 363 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 364 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 365 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 366 | } |
| 367 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 368 | // Note that the pointer written into |*throttler| will only be valid |
| 369 | // for the lifetime of the returned HttpNetworkSession. |
| 370 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 371 | SpdySessionDependencies* session_deps, |
| 372 | TestNetworkStreamThrottler** throttler) { |
| 373 | std::unique_ptr<HttpNetworkSession> session( |
| 374 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 375 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 376 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 377 | *throttler = owned_throttler.get(); |
| 378 | |
| 379 | HttpNetworkSessionPeer peer(session.get()); |
| 380 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 381 | |
| 382 | return session; |
| 383 | } |
| 384 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 385 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 386 | public: |
| 387 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 388 | |
| 389 | // ProxyResolverFactory override. |
| 390 | int CreateProxyResolver( |
| 391 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 392 | std::unique_ptr<ProxyResolver>* result, |
| 393 | const CompletionCallback& callback, |
| 394 | std::unique_ptr<Request>* request) override { |
| 395 | return ERR_PAC_SCRIPT_FAILED; |
| 396 | } |
| 397 | }; |
| 398 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 399 | } // namespace |
| 400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 401 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 402 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 403 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 404 | // Important to restore the per-pool limit first, since the pool limit must |
| 405 | // always be greater than group limit, and the tests reduce both limits. |
| 406 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 407 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 408 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 409 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 410 | } |
| 411 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 412 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 413 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 414 | : ssl_(ASYNC, OK), |
| 415 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 416 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 417 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 418 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 419 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 420 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 421 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 422 | struct SimpleGetHelperResult { |
| 423 | int rv; |
| 424 | std::string status_line; |
| 425 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 426 | int64_t total_received_bytes; |
| 427 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 428 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 429 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 430 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 431 | }; |
| 432 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 433 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 434 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 435 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 436 | } |
| 437 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 438 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 439 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 440 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 441 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 442 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 443 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 444 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 445 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 446 | } |
| 447 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [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 KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 453 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 454 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 455 | // Either |write_failure| specifies a write failure or |read_failure| |
| 456 | // specifies a read failure when using a reused socket. In either case, the |
| 457 | // failure should cause the network transaction to resend the request, and the |
| 458 | // other argument should be NULL. |
| 459 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 460 | const MockRead* read_failure, |
| 461 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 462 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 463 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 464 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 465 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 466 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 467 | HttpRequestInfo request; |
| 468 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 469 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 470 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 471 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 472 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 475 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 476 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 477 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 478 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 480 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 481 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 482 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 483 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 485 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 486 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 488 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 489 | |
| 490 | // Even in the failure cases that use this function, connections are always |
| 491 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 492 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 493 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 494 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 495 | if (out.rv != OK) |
| 496 | return out; |
| 497 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 498 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 499 | // Can't use ASSERT_* inside helper functions like this, so |
| 500 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 501 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 502 | out.rv = ERR_UNEXPECTED; |
| 503 | return out; |
| 504 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 505 | out.status_line = response->headers->GetStatusLine(); |
| 506 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 507 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 508 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 509 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 510 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 511 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 512 | EXPECT_EQ(got_endpoint, |
| 513 | out.remote_endpoint_after_start.address().size() > 0); |
| 514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 515 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 517 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 518 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 519 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 520 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 521 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 522 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 523 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 524 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 525 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 526 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 527 | std::string line; |
| 528 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 529 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 530 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 531 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 532 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 533 | std::string value; |
| 534 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 535 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 536 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 537 | EXPECT_EQ("keep-alive", value); |
| 538 | |
| 539 | std::string response_headers; |
| 540 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 541 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 542 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 544 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 545 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 546 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 548 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 549 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 550 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 551 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 552 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 553 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 554 | MockWrite data_writes[] = { |
| 555 | MockWrite("GET / HTTP/1.1\r\n" |
| 556 | "Host: www.example.org\r\n" |
| 557 | "Connection: keep-alive\r\n\r\n"), |
| 558 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 559 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 560 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 561 | arraysize(data_writes)); |
| 562 | StaticSocketDataProvider* data[] = {&reads}; |
| 563 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 564 | |
| 565 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 566 | out.total_sent_bytes); |
| 567 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 568 | } |
| 569 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 570 | void AddSSLSocketData() { |
| 571 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 572 | ssl_.ssl_info.cert = |
| 573 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 574 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 576 | } |
| 577 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 578 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 579 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 580 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 581 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 582 | |
| 583 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 584 | |
| 585 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 586 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 587 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 588 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 589 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 590 | |
| 591 | // Original socket limits. Some tests set these. Safest to always restore |
| 592 | // them once each test has been run. |
| 593 | int old_max_group_sockets_; |
| 594 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 595 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 596 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 597 | namespace { |
| 598 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 599 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 600 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 601 | BeforeHeadersSentHandler() |
| 602 | : observed_before_headers_sent_with_proxy_(false), |
| 603 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 604 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 605 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 606 | HttpRequestHeaders* request_headers) { |
| 607 | observed_before_headers_sent_ = true; |
| 608 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 609 | !proxy_info.is_quic()) { |
| 610 | return; |
| 611 | } |
| 612 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 613 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 614 | } |
| 615 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 616 | bool observed_before_headers_sent_with_proxy() const { |
| 617 | return observed_before_headers_sent_with_proxy_; |
| 618 | } |
| 619 | |
| 620 | bool observed_before_headers_sent() const { |
| 621 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | std::string observed_proxy_server_uri() const { |
| 625 | return observed_proxy_server_uri_; |
| 626 | } |
| 627 | |
| 628 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 629 | bool observed_before_headers_sent_with_proxy_; |
| 630 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 631 | std::string observed_proxy_server_uri_; |
| 632 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 633 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 634 | }; |
| 635 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 636 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 637 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 638 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 639 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 640 | const int sizeof_row = strlen(row); |
| 641 | const int num_rows = static_cast<int>( |
| 642 | ceil(static_cast<float>(size) / sizeof_row)); |
| 643 | const int sizeof_data = num_rows * sizeof_row; |
| 644 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 645 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 646 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 647 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 648 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 649 | } |
| 650 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 651 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 652 | uint64_t MockGetMSTime() { |
| 653 | // Tue, 23 May 2017 20:13:07 +0000 |
| 654 | return 131400439870000000; |
| 655 | } |
| 656 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 657 | // Alternative functions that eliminate randomness and dependency on the local |
| 658 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 659 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 660 | // This is set to 0xaa because the client challenge for testing in |
| 661 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 662 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 663 | } |
| 664 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 665 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 666 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 667 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 668 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 669 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 670 | template<typename ParentPool> |
| 671 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 672 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 673 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 674 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 675 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 676 | const std::string last_group_name_received() const { |
| 677 | return last_group_name_; |
| 678 | } |
| 679 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 680 | int RequestSocket(const std::string& group_name, |
| 681 | const void* socket_params, |
| 682 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 683 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 684 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 685 | ClientSocketHandle* handle, |
| 686 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 687 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 688 | last_group_name_ = group_name; |
| 689 | return ERR_IO_PENDING; |
| 690 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 691 | void CancelRequest(const std::string& group_name, |
| 692 | ClientSocketHandle* handle) override {} |
| 693 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 694 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 695 | int id) override {} |
| 696 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 697 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 698 | int IdleSocketCount() const override { return 0; } |
| 699 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 700 | return 0; |
| 701 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 702 | LoadState GetLoadState(const std::string& group_name, |
| 703 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 704 | return LOAD_STATE_IDLE; |
| 705 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 706 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 707 | return base::TimeDelta(); |
| 708 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 709 | |
| 710 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 711 | std::string last_group_name_; |
| 712 | }; |
| 713 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 714 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 715 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 716 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 717 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 718 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 719 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 720 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 721 | CaptureGroupNameSSLSocketPool; |
| 722 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 723 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 724 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 725 | HostResolver* host_resolver, |
| 726 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 727 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 728 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 729 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 730 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 731 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 732 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 733 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 734 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 735 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 736 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 737 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 738 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 739 | : SSLClientSocketPool(0, |
| 740 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 741 | cert_verifier, |
| 742 | NULL, |
| 743 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 744 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 745 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 746 | std::string(), |
| 747 | NULL, |
| 748 | NULL, |
| 749 | NULL, |
| 750 | NULL, |
| 751 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 752 | NULL) { |
| 753 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 754 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 755 | //----------------------------------------------------------------------------- |
| 756 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 758 | // configured for common cases. |
| 759 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 760 | if (!auth_challenge) |
| 761 | return false; |
| 762 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 763 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 764 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 765 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 766 | return true; |
| 767 | } |
| 768 | |
| 769 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 770 | if (!auth_challenge) |
| 771 | return false; |
| 772 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 773 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 774 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 775 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 776 | return true; |
| 777 | } |
| 778 | |
| 779 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 780 | if (!auth_challenge) |
| 781 | return false; |
| 782 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 783 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 785 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 786 | return true; |
| 787 | } |
| 788 | |
| 789 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 790 | if (!auth_challenge) |
| 791 | return false; |
| 792 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 793 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 794 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 795 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 796 | return true; |
| 797 | } |
| 798 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 799 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 800 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 801 | if (!auth_challenge) |
| 802 | return false; |
| 803 | EXPECT_FALSE(auth_challenge->is_proxy); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 804 | EXPECT_EQ("https://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 805 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 806 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 807 | return true; |
| 808 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 809 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 810 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 811 | } // namespace |
| 812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 813 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | } |
| 817 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 818 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 820 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 821 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 822 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 823 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 824 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 825 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 826 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 827 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 828 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 829 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 830 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 831 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 832 | |
| 833 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 837 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 838 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 839 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 840 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 841 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 842 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 843 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 844 | EXPECT_THAT(out.rv, IsOk()); |
| 845 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 846 | EXPECT_EQ("hello world", out.response_data); |
| 847 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 848 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 849 | } |
| 850 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 851 | // Response with no status line, and a weird port. Should fail by default. |
| 852 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 853 | MockRead data_reads[] = { |
| 854 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 855 | }; |
| 856 | |
| 857 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 859 | |
| 860 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 861 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 862 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 863 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 864 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 865 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 866 | request.method = "GET"; |
| 867 | request.url = GURL("http://www.example.com:2000/"); |
| 868 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 869 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 870 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 871 | } |
| 872 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 873 | // Tests that request info can be destroyed after the headers phase is complete. |
| 874 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 876 | auto trans = |
| 877 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 878 | |
| 879 | MockRead data_reads[] = { |
| 880 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 881 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 882 | }; |
| 883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 885 | |
| 886 | TestCompletionCallback callback; |
| 887 | |
| 888 | { |
| 889 | auto request = std::make_unique<HttpRequestInfo>(); |
| 890 | request->method = "GET"; |
| 891 | request->url = GURL("http://www.example.org/"); |
| 892 | |
| 893 | int rv = |
| 894 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 895 | |
| 896 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 897 | } // Let request info be destroyed. |
| 898 | |
| 899 | trans.reset(); |
| 900 | } |
| 901 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 902 | // Response with no status line, and a weird port. Option to allow weird ports |
| 903 | // enabled. |
| 904 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 905 | MockRead data_reads[] = { |
| 906 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 907 | }; |
| 908 | |
| 909 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 910 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 911 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 912 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 913 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 914 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 915 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 916 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 917 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 918 | request.method = "GET"; |
| 919 | request.url = GURL("http://www.example.com:2000/"); |
| 920 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 921 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 922 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 923 | |
| 924 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 925 | ASSERT_TRUE(info->headers); |
| 926 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 927 | |
| 928 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 929 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 930 | } |
| 931 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 932 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 933 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 935 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 936 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 937 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 938 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 939 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 940 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 942 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 943 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 944 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 948 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 950 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 951 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 952 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 953 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 954 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 955 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 956 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 957 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 958 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 959 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 963 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 964 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 965 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 966 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 967 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 968 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 969 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 970 | EXPECT_THAT(out.rv, IsOk()); |
| 971 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 972 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 973 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 974 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 978 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 979 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 980 | MockRead("\n"), |
| 981 | MockRead("\n"), |
| 982 | MockRead("Q"), |
| 983 | MockRead("J"), |
| 984 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 985 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 986 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 987 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 988 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 989 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 990 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 991 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 992 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 993 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 997 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 998 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 999 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1000 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 1001 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1002 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1003 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 1004 | EXPECT_THAT(out.rv, IsOk()); |
| 1005 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 1006 | EXPECT_EQ("HTT", out.response_data); |
| 1007 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1008 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1009 | } |
| 1010 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1011 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 1012 | // persistent connection. The response should still terminate since a 204 |
| 1013 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1014 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1015 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1016 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1017 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1018 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1020 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1021 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1022 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1023 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1024 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1025 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1026 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1027 | int64_t response_size = reads_size - strlen(junk); |
| 1028 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1029 | } |
| 1030 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1031 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1032 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1033 | std::string final_chunk = "0\r\n\r\n"; |
| 1034 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1035 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1036 | MockRead data_reads[] = { |
| 1037 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1038 | MockRead("5\r\nHello\r\n"), |
| 1039 | MockRead("1\r\n"), |
| 1040 | MockRead(" \r\n"), |
| 1041 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1042 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1043 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1044 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1045 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1046 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1047 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1048 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1049 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1050 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1051 | int64_t response_size = reads_size - extra_data.size(); |
| 1052 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1055 | // Next tests deal with http://crbug.com/56344. |
| 1056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1057 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1058 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1059 | MockRead data_reads[] = { |
| 1060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1061 | MockRead("Content-Length: 10\r\n"), |
| 1062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1063 | }; |
| 1064 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1065 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1066 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1067 | } |
| 1068 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1069 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1070 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1071 | MockRead data_reads[] = { |
| 1072 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1073 | MockRead("Content-Length: 5\r\n"), |
| 1074 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1075 | MockRead("Hello"), |
| 1076 | }; |
| 1077 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1078 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1079 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1080 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1081 | EXPECT_EQ("Hello", out.response_data); |
| 1082 | } |
| 1083 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1084 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1085 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1086 | // More than 2 dupes. |
| 1087 | { |
| 1088 | MockRead data_reads[] = { |
| 1089 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1090 | MockRead("Content-Length: 5\r\n"), |
| 1091 | MockRead("Content-Length: 5\r\n"), |
| 1092 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1093 | MockRead("Hello"), |
| 1094 | }; |
| 1095 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1096 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1097 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1098 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1099 | EXPECT_EQ("Hello", out.response_data); |
| 1100 | } |
| 1101 | // HTTP/1.0 |
| 1102 | { |
| 1103 | MockRead data_reads[] = { |
| 1104 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1105 | MockRead("Content-Length: 5\r\n"), |
| 1106 | MockRead("Content-Length: 5\r\n"), |
| 1107 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1108 | MockRead("Hello"), |
| 1109 | }; |
| 1110 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1111 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1112 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1113 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1114 | EXPECT_EQ("Hello", out.response_data); |
| 1115 | } |
| 1116 | // 2 dupes and one mismatched. |
| 1117 | { |
| 1118 | MockRead data_reads[] = { |
| 1119 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1120 | MockRead("Content-Length: 10\r\n"), |
| 1121 | MockRead("Content-Length: 10\r\n"), |
| 1122 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1123 | }; |
| 1124 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1125 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1126 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1130 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1131 | MultipleContentLengthHeadersTransferEncoding) { |
| 1132 | MockRead data_reads[] = { |
| 1133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1134 | MockRead("Content-Length: 666\r\n"), |
| 1135 | MockRead("Content-Length: 1337\r\n"), |
| 1136 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1137 | MockRead("5\r\nHello\r\n"), |
| 1138 | MockRead("1\r\n"), |
| 1139 | MockRead(" \r\n"), |
| 1140 | MockRead("5\r\nworld\r\n"), |
| 1141 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1142 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1143 | }; |
| 1144 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1145 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1146 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1147 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1148 | EXPECT_EQ("Hello world", out.response_data); |
| 1149 | } |
| 1150 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | // Next tests deal with http://crbug.com/98895. |
| 1152 | |
| 1153 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1154 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1155 | MockRead data_reads[] = { |
| 1156 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1157 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1158 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1159 | MockRead("Hello"), |
| 1160 | }; |
| 1161 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1162 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1163 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1164 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1165 | EXPECT_EQ("Hello", out.response_data); |
| 1166 | } |
| 1167 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1168 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1169 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | MockRead data_reads[] = { |
| 1171 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1172 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1173 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1174 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1175 | MockRead("Hello"), |
| 1176 | }; |
| 1177 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1178 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1179 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1180 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1181 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1185 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1186 | MockRead data_reads[] = { |
| 1187 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1188 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1189 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1190 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1191 | MockRead("Hello"), |
| 1192 | }; |
| 1193 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1194 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1195 | EXPECT_THAT(out.rv, |
| 1196 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | } |
| 1198 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1199 | // Checks that two identical Location headers result in no error. |
| 1200 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1201 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1202 | MockRead data_reads[] = { |
| 1203 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1204 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1205 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1207 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | }; |
| 1209 | |
| 1210 | HttpRequestInfo request; |
| 1211 | request.method = "GET"; |
| 1212 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1213 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1214 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1215 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1216 | |
| 1217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1219 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1220 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1221 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1222 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1224 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1225 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1227 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1228 | ASSERT_TRUE(response); |
| 1229 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1230 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1231 | std::string url; |
| 1232 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1233 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1234 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1235 | } |
| 1236 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1237 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1238 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1239 | MockRead data_reads[] = { |
| 1240 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1241 | MockRead("Location: http://good.com/\r\n"), |
| 1242 | MockRead("Location: http://evil.com/\r\n"), |
| 1243 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1244 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1245 | }; |
| 1246 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1247 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1248 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1249 | } |
| 1250 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1252 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1253 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1254 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1256 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1258 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1259 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1260 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1261 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1262 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1263 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1264 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1265 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1266 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1267 | "Host: www.example.org\r\n" |
| 1268 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1269 | }; |
| 1270 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1271 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1272 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1273 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1274 | // No response body because the test stops reading here. |
| 1275 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1276 | }; |
| 1277 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1278 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1279 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1280 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1282 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1284 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1286 | |
| 1287 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1288 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1291 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1292 | |
| 1293 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1294 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1295 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1296 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1297 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1298 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1299 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1300 | |
| 1301 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1302 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1303 | bool has_server_header = response->headers->EnumerateHeader( |
| 1304 | &iter, "Server", &server_header); |
| 1305 | EXPECT_TRUE(has_server_header); |
| 1306 | EXPECT_EQ("Blah", server_header); |
| 1307 | |
| 1308 | // Reading should give EOF right away, since there is no message body |
| 1309 | // (despite non-zero content-length). |
| 1310 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1312 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1313 | EXPECT_EQ("", response_data); |
| 1314 | } |
| 1315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1316 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
| 1319 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1320 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1321 | MockRead("hello"), |
| 1322 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1323 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1324 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1326 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1329 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | "hello", "world" |
| 1331 | }; |
| 1332 | |
| 1333 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1334 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1335 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1336 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1340 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1342 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1343 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | |
| 1345 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1346 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1348 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1349 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1351 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1352 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1353 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1354 | |
| 1355 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1356 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1358 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1359 | } |
| 1360 | } |
| 1361 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1362 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1363 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1364 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1365 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1366 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1367 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1368 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | request.method = "POST"; |
| 1370 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1371 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1373 | // Check the upload progress returned before initialization is correct. |
| 1374 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1375 | EXPECT_EQ(0u, progress.size()); |
| 1376 | EXPECT_EQ(0u, progress.position()); |
| 1377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1380 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1381 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1382 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1383 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1384 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1385 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1386 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1390 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1392 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1394 | |
| 1395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1396 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1399 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1400 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1401 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1402 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1403 | |
| 1404 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1405 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1407 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1408 | } |
| 1409 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1410 | // This test is almost the same as Ignores100 above, but the response contains |
| 1411 | // 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] | 1412 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1413 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1414 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1415 | request.method = "GET"; |
| 1416 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1419 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1420 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1421 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1422 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1423 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1424 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1426 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1427 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1429 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1430 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1431 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1432 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1434 | |
| 1435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1438 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1439 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1440 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1441 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1442 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1443 | |
| 1444 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1445 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1447 | EXPECT_EQ("hello world", response_data); |
| 1448 | } |
| 1449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1450 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1451 | HttpRequestInfo request; |
| 1452 | request.method = "POST"; |
| 1453 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1454 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1457 | |
| 1458 | MockRead data_reads[] = { |
| 1459 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1460 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1461 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1462 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1463 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1464 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1465 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1466 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1467 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1469 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1470 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1471 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1472 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1473 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1474 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1475 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1476 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1477 | } |
| 1478 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1479 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1480 | HttpRequestInfo request; |
| 1481 | request.method = "POST"; |
| 1482 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1483 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1486 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1487 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1488 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1489 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1490 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1491 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1493 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1494 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1495 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1496 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1497 | |
| 1498 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1499 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1500 | } |
| 1501 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1502 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1503 | const MockWrite* write_failure, |
| 1504 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1505 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1506 | request.method = "GET"; |
| 1507 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1508 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1509 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1510 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1512 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1513 | // Written data for successfully sending both requests. |
| 1514 | MockWrite data1_writes[] = { |
| 1515 | MockWrite("GET / HTTP/1.1\r\n" |
| 1516 | "Host: www.foo.com\r\n" |
| 1517 | "Connection: keep-alive\r\n\r\n"), |
| 1518 | MockWrite("GET / HTTP/1.1\r\n" |
| 1519 | "Host: www.foo.com\r\n" |
| 1520 | "Connection: keep-alive\r\n\r\n") |
| 1521 | }; |
| 1522 | |
| 1523 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1524 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1525 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1526 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1527 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1528 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1529 | |
| 1530 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1531 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1532 | data1_writes[1] = *write_failure; |
| 1533 | } else { |
| 1534 | ASSERT_TRUE(read_failure); |
| 1535 | data1_reads[2] = *read_failure; |
| 1536 | } |
| 1537 | |
| 1538 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1539 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1540 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1541 | |
| 1542 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1543 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1544 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1545 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1546 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1547 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1548 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1549 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1550 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1551 | "hello", "world" |
| 1552 | }; |
| 1553 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1554 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1555 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1556 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1562 | |
| 1563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1564 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1565 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1566 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1567 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1568 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1569 | if (i == 0) { |
| 1570 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1571 | } else { |
| 1572 | // The second request should be using a new socket. |
| 1573 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1574 | } |
| 1575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1576 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1577 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1578 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1579 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1580 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1581 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1582 | |
| 1583 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1584 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1585 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1586 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1587 | } |
| 1588 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1589 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1590 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1591 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1592 | const MockRead* read_failure, |
| 1593 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1594 | HttpRequestInfo request; |
| 1595 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1596 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1597 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1598 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1599 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1601 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1602 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1603 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1604 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1605 | ssl1.next_proto = kProtoHTTP2; |
| 1606 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1607 | } |
| 1608 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1610 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1611 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1612 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1613 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1614 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1615 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1616 | SpdySerializedFrame spdy_data( |
| 1617 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1618 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1619 | // HTTP/1.1 versions of the request and response. |
| 1620 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1621 | "Host: www.foo.com\r\n" |
| 1622 | "Connection: keep-alive\r\n\r\n"; |
| 1623 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1624 | const char kHttpData[] = "hello"; |
| 1625 | |
| 1626 | std::vector<MockRead> data1_reads; |
| 1627 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1628 | if (write_failure) { |
| 1629 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1630 | data1_writes.push_back(*write_failure); |
| 1631 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1632 | } else { |
| 1633 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1634 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1635 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1636 | } else { |
| 1637 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1638 | } |
| 1639 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1640 | } |
| 1641 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1642 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1643 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1645 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1646 | std::vector<MockRead> data2_reads; |
| 1647 | std::vector<MockWrite> data2_writes; |
| 1648 | |
| 1649 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1650 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1651 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1652 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1653 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1654 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1655 | } else { |
| 1656 | data2_writes.push_back( |
| 1657 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1658 | |
| 1659 | data2_reads.push_back( |
| 1660 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1661 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1662 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1663 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1664 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1665 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1666 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1667 | |
| 1668 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1669 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1670 | // Wait for the preconnect to complete. |
| 1671 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1672 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1673 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1674 | |
| 1675 | // Make the request. |
| 1676 | TestCompletionCallback callback; |
| 1677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1680 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1682 | |
| 1683 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1684 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1685 | |
| 1686 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1687 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1688 | TestLoadTimingNotReused( |
| 1689 | load_timing_info, |
| 1690 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1692 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1693 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1694 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1695 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1696 | if (response->was_fetched_via_spdy) { |
| 1697 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1698 | } else { |
| 1699 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1700 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1701 | |
| 1702 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1703 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1704 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1705 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1706 | } |
| 1707 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1708 | // Test that we do not retry indefinitely when a server sends an error like |
| 1709 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1710 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1711 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1712 | HttpRequestInfo request; |
| 1713 | request.method = "GET"; |
| 1714 | request.url = GURL("https://www.foo.com/"); |
| 1715 | |
| 1716 | // Check whether we give up after the third try. |
| 1717 | |
| 1718 | // Construct an HTTP2 request and a "Go away" response. |
| 1719 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1720 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1721 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1722 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1723 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1724 | |
| 1725 | // Three go away responses. |
| 1726 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1727 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1728 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1729 | |
| 1730 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1731 | AddSSLSocketData(); |
| 1732 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1733 | AddSSLSocketData(); |
| 1734 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1735 | AddSSLSocketData(); |
| 1736 | |
| 1737 | TestCompletionCallback callback; |
| 1738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1740 | |
| 1741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1743 | |
| 1744 | rv = callback.WaitForResult(); |
| 1745 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1746 | } |
| 1747 | |
| 1748 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1749 | HttpRequestInfo request; |
| 1750 | request.method = "GET"; |
| 1751 | request.url = GURL("https://www.foo.com/"); |
| 1752 | |
| 1753 | // Check whether we try atleast thrice before giving up. |
| 1754 | |
| 1755 | // Construct an HTTP2 request and a "Go away" response. |
| 1756 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1757 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1758 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1759 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1760 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1761 | |
| 1762 | // Construct a non error HTTP2 response. |
| 1763 | SpdySerializedFrame spdy_response_no_error( |
| 1764 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1765 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1766 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1767 | CreateMockRead(spdy_data, 2)}; |
| 1768 | |
| 1769 | // Two error responses. |
| 1770 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1771 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1772 | // Followed by a success response. |
| 1773 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1774 | |
| 1775 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1776 | AddSSLSocketData(); |
| 1777 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1778 | AddSSLSocketData(); |
| 1779 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1780 | AddSSLSocketData(); |
| 1781 | |
| 1782 | TestCompletionCallback callback; |
| 1783 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1785 | |
| 1786 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1788 | |
| 1789 | rv = callback.WaitForResult(); |
| 1790 | EXPECT_THAT(rv, IsOk()); |
| 1791 | } |
| 1792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1793 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1794 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1795 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1796 | } |
| 1797 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1798 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1799 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1800 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1801 | } |
| 1802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1803 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1804 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1805 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1806 | } |
| 1807 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1808 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1809 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1810 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1811 | MockRead read_failure(SYNCHRONOUS, |
| 1812 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1813 | "Connection: Keep-Alive\r\n" |
| 1814 | "Content-Length: 6\r\n\r\n" |
| 1815 | "Pickle"); |
| 1816 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1817 | } |
| 1818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1819 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1820 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1821 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1822 | } |
| 1823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1824 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1825 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1826 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1827 | } |
| 1828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1829 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1830 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1831 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1832 | } |
| 1833 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1834 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1835 | MockRead read_failure(ASYNC, OK); // EOF |
| 1836 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1837 | } |
| 1838 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1839 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1840 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1841 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1842 | MockRead read_failure(SYNCHRONOUS, |
| 1843 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1844 | "Connection: Keep-Alive\r\n" |
| 1845 | "Content-Length: 6\r\n\r\n" |
| 1846 | "Pickle"); |
| 1847 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1848 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1849 | } |
| 1850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1851 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1852 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1853 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1854 | } |
| 1855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1856 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1857 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1858 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1859 | } |
| 1860 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1861 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1862 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1863 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1864 | } |
| 1865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1866 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1867 | MockRead read_failure(ASYNC, OK); // EOF |
| 1868 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1869 | } |
| 1870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1871 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1872 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1874 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1875 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1878 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1879 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1880 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1881 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1882 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1883 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1884 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1885 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1888 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1889 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1890 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1892 | |
| 1893 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1894 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1895 | |
| 1896 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1897 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1898 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | // What do various browsers do when the server closes a non-keepalive |
| 1902 | // connection without sending any response header or body? |
| 1903 | // |
| 1904 | // IE7: error page |
| 1905 | // Safari 3.1.2 (Windows): error page |
| 1906 | // Firefox 3.0.1: blank page |
| 1907 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1908 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1909 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1910 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1911 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1912 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1913 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1914 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1915 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1916 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1917 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1918 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1919 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1920 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1921 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1922 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1923 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1924 | // destructor in such situations. |
| 1925 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1926 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1927 | HttpRequestInfo request; |
| 1928 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1929 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1932 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1933 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1934 | |
| 1935 | MockRead data_reads[] = { |
| 1936 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1937 | MockRead("Connection: keep-alive\r\n"), |
| 1938 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1939 | MockRead("hello"), |
| 1940 | MockRead(SYNCHRONOUS, 0), |
| 1941 | }; |
| 1942 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1943 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1944 | |
| 1945 | TestCompletionCallback callback; |
| 1946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1947 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1949 | |
| 1950 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1951 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1952 | |
| 1953 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1954 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1955 | if (rv == ERR_IO_PENDING) |
| 1956 | rv = callback.WaitForResult(); |
| 1957 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1958 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1959 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1960 | |
| 1961 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1962 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1963 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1964 | } |
| 1965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1966 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1967 | HttpRequestInfo request; |
| 1968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1969 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1970 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1972 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1973 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1974 | |
| 1975 | MockRead data_reads[] = { |
| 1976 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1977 | MockRead("Connection: keep-alive\r\n"), |
| 1978 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1979 | MockRead(SYNCHRONOUS, 0), |
| 1980 | }; |
| 1981 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1983 | |
| 1984 | TestCompletionCallback callback; |
| 1985 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1986 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1988 | |
| 1989 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1990 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1991 | |
| 1992 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1993 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1994 | if (rv == ERR_IO_PENDING) |
| 1995 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1996 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1997 | |
| 1998 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1999 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2000 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2001 | } |
| 2002 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2003 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2004 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2005 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2006 | HttpRequestInfo request; |
| 2007 | request.method = "GET"; |
| 2008 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2009 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2010 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2011 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2013 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2014 | const char* request_data = |
| 2015 | "GET / HTTP/1.1\r\n" |
| 2016 | "Host: www.foo.com\r\n" |
| 2017 | "Connection: keep-alive\r\n\r\n"; |
| 2018 | MockWrite data_writes[] = { |
| 2019 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2020 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2021 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2022 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2023 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2024 | }; |
| 2025 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2026 | // Note that because all these reads happen in the same |
| 2027 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2028 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2029 | MockRead data_reads[] = { |
| 2030 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2031 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2032 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2033 | MockRead(ASYNC, 7, |
| 2034 | "HTTP/1.1 302 Found\r\n" |
| 2035 | "Content-Length: 0\r\n\r\n"), |
| 2036 | MockRead(ASYNC, 9, |
| 2037 | "HTTP/1.1 302 Found\r\n" |
| 2038 | "Content-Length: 5\r\n\r\n" |
| 2039 | "hello"), |
| 2040 | MockRead(ASYNC, 11, |
| 2041 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2042 | "Content-Length: 0\r\n\r\n"), |
| 2043 | MockRead(ASYNC, 13, |
| 2044 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2045 | "Content-Length: 5\r\n\r\n" |
| 2046 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2047 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2048 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2049 | // the set_busy_before_sync_reads(true) call, while the |
| 2050 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2051 | // reuseable. See http://crbug.com/544255. |
| 2052 | MockRead(ASYNC, 15, |
| 2053 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2054 | "Content-Length: 5\r\n\r\n"), |
| 2055 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2056 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2057 | MockRead(ASYNC, 18, |
| 2058 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2059 | "Content-Length: 5\r\n\r\n" |
| 2060 | "he"), |
| 2061 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2062 | |
| 2063 | // The body of the final request is actually read. |
| 2064 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2065 | MockRead(ASYNC, 22, "hello"), |
| 2066 | }; |
| 2067 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2068 | arraysize(data_writes)); |
| 2069 | data.set_busy_before_sync_reads(true); |
| 2070 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2071 | |
| 2072 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2073 | std::string response_lines[kNumUnreadBodies]; |
| 2074 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2075 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2076 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2077 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2078 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2079 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2080 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2082 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2083 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2084 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2085 | LoadTimingInfo load_timing_info; |
| 2086 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2087 | if (i == 0) { |
| 2088 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2089 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2090 | } else { |
| 2091 | TestLoadTimingReused(load_timing_info); |
| 2092 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2093 | } |
| 2094 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2095 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2096 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2097 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2098 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2099 | response_lines[i] = response->headers->GetStatusLine(); |
| 2100 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2101 | // Delete the transaction without reading the response bodies. Then spin |
| 2102 | // the message loop, so the response bodies are drained. |
| 2103 | trans.reset(); |
| 2104 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2105 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2106 | |
| 2107 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2108 | "HTTP/1.1 204 No Content", |
| 2109 | "HTTP/1.1 205 Reset Content", |
| 2110 | "HTTP/1.1 304 Not Modified", |
| 2111 | "HTTP/1.1 302 Found", |
| 2112 | "HTTP/1.1 302 Found", |
| 2113 | "HTTP/1.1 301 Moved Permanently", |
| 2114 | "HTTP/1.1 301 Moved Permanently", |
| 2115 | "HTTP/1.1 200 Hunky-Dory", |
| 2116 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2117 | }; |
| 2118 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2119 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2120 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2121 | |
| 2122 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2123 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2124 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2125 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2128 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2129 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2130 | ASSERT_TRUE(response); |
| 2131 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2132 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2133 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2134 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2136 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2137 | } |
| 2138 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2139 | // Sockets that receive extra data after a response is complete should not be |
| 2140 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2141 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2142 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2143 | MockWrite data_writes1[] = { |
| 2144 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2145 | "Host: www.borked.com\r\n" |
| 2146 | "Connection: keep-alive\r\n\r\n"), |
| 2147 | }; |
| 2148 | |
| 2149 | MockRead data_reads1[] = { |
| 2150 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2151 | "Connection: keep-alive\r\n" |
| 2152 | "Content-Length: 22\r\n\r\n" |
| 2153 | "This server is borked."), |
| 2154 | }; |
| 2155 | |
| 2156 | MockWrite data_writes2[] = { |
| 2157 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2158 | "Host: www.borked.com\r\n" |
| 2159 | "Connection: keep-alive\r\n\r\n"), |
| 2160 | }; |
| 2161 | |
| 2162 | MockRead data_reads2[] = { |
| 2163 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2164 | "Content-Length: 3\r\n\r\n" |
| 2165 | "foo"), |
| 2166 | }; |
| 2167 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2168 | data_writes1, arraysize(data_writes1)); |
| 2169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2170 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2171 | data_writes2, arraysize(data_writes2)); |
| 2172 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2173 | |
| 2174 | TestCompletionCallback callback; |
| 2175 | HttpRequestInfo request1; |
| 2176 | request1.method = "HEAD"; |
| 2177 | request1.url = GURL("http://www.borked.com/"); |
| 2178 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2179 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2180 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2181 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2182 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2183 | |
| 2184 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2185 | ASSERT_TRUE(response1); |
| 2186 | ASSERT_TRUE(response1->headers); |
| 2187 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2188 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2189 | |
| 2190 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2191 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2192 | EXPECT_EQ("", response_data1); |
| 2193 | // Deleting the transaction attempts to release the socket back into the |
| 2194 | // socket pool. |
| 2195 | trans1.reset(); |
| 2196 | |
| 2197 | HttpRequestInfo request2; |
| 2198 | request2.method = "GET"; |
| 2199 | request2.url = GURL("http://www.borked.com/foo"); |
| 2200 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2201 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2202 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2203 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2204 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2205 | |
| 2206 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2207 | ASSERT_TRUE(response2); |
| 2208 | ASSERT_TRUE(response2->headers); |
| 2209 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2210 | |
| 2211 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2212 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2213 | EXPECT_EQ("foo", response_data2); |
| 2214 | } |
| 2215 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2216 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2218 | MockWrite data_writes1[] = { |
| 2219 | MockWrite("GET / HTTP/1.1\r\n" |
| 2220 | "Host: www.borked.com\r\n" |
| 2221 | "Connection: keep-alive\r\n\r\n"), |
| 2222 | }; |
| 2223 | |
| 2224 | MockRead data_reads1[] = { |
| 2225 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2226 | "Connection: keep-alive\r\n" |
| 2227 | "Content-Length: 22\r\n\r\n" |
| 2228 | "This server is borked." |
| 2229 | "Bonus data!"), |
| 2230 | }; |
| 2231 | |
| 2232 | MockWrite data_writes2[] = { |
| 2233 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2234 | "Host: www.borked.com\r\n" |
| 2235 | "Connection: keep-alive\r\n\r\n"), |
| 2236 | }; |
| 2237 | |
| 2238 | MockRead data_reads2[] = { |
| 2239 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2240 | "Content-Length: 3\r\n\r\n" |
| 2241 | "foo"), |
| 2242 | }; |
| 2243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2244 | data_writes1, arraysize(data_writes1)); |
| 2245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2246 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2247 | data_writes2, arraysize(data_writes2)); |
| 2248 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2249 | |
| 2250 | TestCompletionCallback callback; |
| 2251 | HttpRequestInfo request1; |
| 2252 | request1.method = "GET"; |
| 2253 | request1.url = GURL("http://www.borked.com/"); |
| 2254 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2255 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2256 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2257 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2258 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2259 | |
| 2260 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2261 | ASSERT_TRUE(response1); |
| 2262 | ASSERT_TRUE(response1->headers); |
| 2263 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2264 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2265 | |
| 2266 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2267 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2268 | EXPECT_EQ("This server is borked.", response_data1); |
| 2269 | // Deleting the transaction attempts to release the socket back into the |
| 2270 | // socket pool. |
| 2271 | trans1.reset(); |
| 2272 | |
| 2273 | HttpRequestInfo request2; |
| 2274 | request2.method = "GET"; |
| 2275 | request2.url = GURL("http://www.borked.com/foo"); |
| 2276 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2277 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2279 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2280 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2281 | |
| 2282 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2283 | ASSERT_TRUE(response2); |
| 2284 | ASSERT_TRUE(response2->headers); |
| 2285 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2286 | |
| 2287 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2288 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2289 | EXPECT_EQ("foo", response_data2); |
| 2290 | } |
| 2291 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2292 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2294 | MockWrite data_writes1[] = { |
| 2295 | MockWrite("GET / HTTP/1.1\r\n" |
| 2296 | "Host: www.borked.com\r\n" |
| 2297 | "Connection: keep-alive\r\n\r\n"), |
| 2298 | }; |
| 2299 | |
| 2300 | MockRead data_reads1[] = { |
| 2301 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2302 | "Connection: keep-alive\r\n" |
| 2303 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2304 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2305 | MockRead("0\r\n\r\nBonus data!"), |
| 2306 | }; |
| 2307 | |
| 2308 | MockWrite data_writes2[] = { |
| 2309 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2310 | "Host: www.borked.com\r\n" |
| 2311 | "Connection: keep-alive\r\n\r\n"), |
| 2312 | }; |
| 2313 | |
| 2314 | MockRead data_reads2[] = { |
| 2315 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2316 | "Content-Length: 3\r\n\r\n" |
| 2317 | "foo"), |
| 2318 | }; |
| 2319 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2320 | data_writes1, arraysize(data_writes1)); |
| 2321 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2322 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2323 | data_writes2, arraysize(data_writes2)); |
| 2324 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2325 | |
| 2326 | TestCompletionCallback callback; |
| 2327 | HttpRequestInfo request1; |
| 2328 | request1.method = "GET"; |
| 2329 | request1.url = GURL("http://www.borked.com/"); |
| 2330 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2331 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2332 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2333 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2334 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2335 | |
| 2336 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2337 | ASSERT_TRUE(response1); |
| 2338 | ASSERT_TRUE(response1->headers); |
| 2339 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2340 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2341 | |
| 2342 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2343 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2344 | EXPECT_EQ("This server is borked.", response_data1); |
| 2345 | // Deleting the transaction attempts to release the socket back into the |
| 2346 | // socket pool. |
| 2347 | trans1.reset(); |
| 2348 | |
| 2349 | HttpRequestInfo request2; |
| 2350 | request2.method = "GET"; |
| 2351 | request2.url = GURL("http://www.borked.com/foo"); |
| 2352 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2353 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2354 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2355 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2357 | |
| 2358 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2359 | ASSERT_TRUE(response2); |
| 2360 | ASSERT_TRUE(response2->headers); |
| 2361 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2362 | |
| 2363 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2364 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2365 | EXPECT_EQ("foo", response_data2); |
| 2366 | } |
| 2367 | |
| 2368 | // This is a little different from the others - it tests the case that the |
| 2369 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2370 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2371 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2372 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2374 | MockWrite data_writes1[] = { |
| 2375 | MockWrite("GET / HTTP/1.1\r\n" |
| 2376 | "Host: www.borked.com\r\n" |
| 2377 | "Connection: keep-alive\r\n\r\n"), |
| 2378 | }; |
| 2379 | |
| 2380 | MockRead data_reads1[] = { |
| 2381 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2382 | "Connection: keep-alive\r\n" |
| 2383 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2384 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2385 | MockRead("0\r\n\r\nBonus data!"), |
| 2386 | }; |
| 2387 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2388 | data_writes1, arraysize(data_writes1)); |
| 2389 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2390 | |
| 2391 | TestCompletionCallback callback; |
| 2392 | HttpRequestInfo request1; |
| 2393 | request1.method = "GET"; |
| 2394 | request1.url = GURL("http://www.borked.com/"); |
| 2395 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2396 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2397 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2398 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2399 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2400 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2401 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2402 | ASSERT_TRUE(response1); |
| 2403 | ASSERT_TRUE(response1->headers); |
| 2404 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2405 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2406 | |
| 2407 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2408 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2409 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2410 | |
| 2411 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2412 | // socket can't be reused, rather than returning it to the socket pool. |
| 2413 | base::RunLoop().RunUntilIdle(); |
| 2414 | |
| 2415 | // There should be no idle sockets in the pool. |
| 2416 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2417 | } |
| 2418 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2419 | // Test the request-challenge-retry sequence for basic auth. |
| 2420 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2421 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2422 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2424 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2425 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2426 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2427 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2428 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2429 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2430 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2431 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2432 | MockWrite( |
| 2433 | "GET / HTTP/1.1\r\n" |
| 2434 | "Host: www.example.org\r\n" |
| 2435 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2436 | }; |
| 2437 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2438 | MockRead data_reads1[] = { |
| 2439 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2440 | // Give a couple authenticate options (only the middle one is actually |
| 2441 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2442 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2443 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2444 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2445 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2446 | // Large content-length -- won't matter, as connection will be reset. |
| 2447 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2448 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2449 | }; |
| 2450 | |
| 2451 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2452 | // be issuing -- the final header line contains the credentials. |
| 2453 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2454 | MockWrite( |
| 2455 | "GET / HTTP/1.1\r\n" |
| 2456 | "Host: www.example.org\r\n" |
| 2457 | "Connection: keep-alive\r\n" |
| 2458 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2459 | }; |
| 2460 | |
| 2461 | // Lastly, the server responds with the actual content. |
| 2462 | MockRead data_reads2[] = { |
| 2463 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2464 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2465 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2466 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2467 | }; |
| 2468 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2469 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2470 | data_writes1, arraysize(data_writes1)); |
| 2471 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2472 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2473 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2474 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2476 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2478 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2480 | |
| 2481 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2483 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2484 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2485 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2486 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2487 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2488 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2489 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2490 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2491 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2493 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2494 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2495 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2497 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2499 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2501 | |
| 2502 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2503 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2504 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2505 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2506 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2507 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2508 | // The load timing after restart should have a new socket ID, and times after |
| 2509 | // those of the first load timing. |
| 2510 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2511 | load_timing_info2.connect_timing.connect_start); |
| 2512 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2513 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2514 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2515 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2516 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2517 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2519 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2520 | ASSERT_TRUE(response); |
| 2521 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2522 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2523 | } |
| 2524 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2525 | // Test the request-challenge-retry sequence for basic auth. |
| 2526 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2527 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2528 | HttpRequestInfo request; |
| 2529 | request.method = "GET"; |
| 2530 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2531 | |
| 2532 | TestNetLog log; |
| 2533 | MockHostResolver* resolver = new MockHostResolver(); |
| 2534 | session_deps_.net_log = &log; |
| 2535 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2536 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2538 | |
| 2539 | resolver->rules()->ClearRules(); |
| 2540 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2541 | |
| 2542 | MockWrite data_writes1[] = { |
| 2543 | MockWrite("GET / HTTP/1.1\r\n" |
| 2544 | "Host: www.example.org\r\n" |
| 2545 | "Connection: keep-alive\r\n\r\n"), |
| 2546 | }; |
| 2547 | |
| 2548 | MockRead data_reads1[] = { |
| 2549 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2550 | // Give a couple authenticate options (only the middle one is actually |
| 2551 | // supported). |
| 2552 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2553 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2554 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2555 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2556 | // Large content-length -- won't matter, as connection will be reset. |
| 2557 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2558 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2559 | }; |
| 2560 | |
| 2561 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2562 | // be issuing -- the final header line contains the credentials. |
| 2563 | MockWrite data_writes2[] = { |
| 2564 | MockWrite("GET / HTTP/1.1\r\n" |
| 2565 | "Host: www.example.org\r\n" |
| 2566 | "Connection: keep-alive\r\n" |
| 2567 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2568 | }; |
| 2569 | |
| 2570 | // Lastly, the server responds with the actual content. |
| 2571 | MockRead data_reads2[] = { |
| 2572 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2573 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2574 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2575 | }; |
| 2576 | |
| 2577 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2578 | data_writes1, arraysize(data_writes1)); |
| 2579 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2580 | data_writes2, arraysize(data_writes2)); |
| 2581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2582 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2583 | |
| 2584 | TestCompletionCallback callback1; |
| 2585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2586 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2587 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2588 | |
| 2589 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2590 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2591 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2592 | |
| 2593 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2594 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2595 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2596 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2598 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2599 | ASSERT_TRUE(response); |
| 2600 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2601 | |
| 2602 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2603 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2604 | ASSERT_FALSE(endpoint.address().empty()); |
| 2605 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2606 | |
| 2607 | resolver->rules()->ClearRules(); |
| 2608 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2609 | |
| 2610 | TestCompletionCallback callback2; |
| 2611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2612 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2613 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2614 | |
| 2615 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2616 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2617 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2618 | // The load timing after restart should have a new socket ID, and times after |
| 2619 | // those of the first load timing. |
| 2620 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2621 | load_timing_info2.connect_timing.connect_start); |
| 2622 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2623 | |
| 2624 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2625 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2626 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2627 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2628 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2629 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2630 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2631 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2632 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2634 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2635 | ASSERT_FALSE(endpoint.address().empty()); |
| 2636 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2637 | } |
| 2638 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2639 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2640 | HttpRequestInfo request; |
| 2641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2642 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2643 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2647 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2648 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2649 | MockWrite( |
| 2650 | "GET / HTTP/1.1\r\n" |
| 2651 | "Host: www.example.org\r\n" |
| 2652 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2653 | }; |
| 2654 | |
| 2655 | MockRead data_reads[] = { |
| 2656 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2657 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2658 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2659 | // Large content-length -- won't matter, as connection will be reset. |
| 2660 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2661 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2662 | }; |
| 2663 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2665 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2667 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2671 | |
| 2672 | rv = callback.WaitForResult(); |
| 2673 | EXPECT_EQ(0, rv); |
| 2674 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2675 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2676 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2677 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2678 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2680 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2681 | ASSERT_TRUE(response); |
| 2682 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2683 | } |
| 2684 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2685 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2686 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2687 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2688 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2689 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2690 | // reused. See http://crbug.com/544255. |
| 2691 | for (int i = 0; i < 2; ++i) { |
| 2692 | HttpRequestInfo request; |
| 2693 | request.method = "GET"; |
| 2694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2695 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2696 | TestNetLog log; |
| 2697 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2699 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2700 | MockWrite data_writes[] = { |
| 2701 | MockWrite(ASYNC, 0, |
| 2702 | "GET / HTTP/1.1\r\n" |
| 2703 | "Host: www.example.org\r\n" |
| 2704 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2706 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2707 | // be issuing -- the final header line contains the credentials. |
| 2708 | MockWrite(ASYNC, 6, |
| 2709 | "GET / HTTP/1.1\r\n" |
| 2710 | "Host: www.example.org\r\n" |
| 2711 | "Connection: keep-alive\r\n" |
| 2712 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2713 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2715 | MockRead data_reads[] = { |
| 2716 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2717 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2718 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2719 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2720 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2721 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2722 | // Lastly, the server responds with the actual content. |
| 2723 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2724 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2725 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2726 | MockRead(ASYNC, 10, "Hello"), |
| 2727 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2728 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2729 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2730 | arraysize(data_writes)); |
| 2731 | data.set_busy_before_sync_reads(true); |
| 2732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2733 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2734 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2735 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2737 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2738 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2740 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2742 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2745 | ASSERT_TRUE(response); |
| 2746 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2748 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2750 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2751 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2752 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2753 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2754 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2755 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2756 | TestLoadTimingReused(load_timing_info2); |
| 2757 | // The load timing after restart should have the same socket ID, and times |
| 2758 | // those of the first load timing. |
| 2759 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2760 | load_timing_info2.send_start); |
| 2761 | 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] | 2762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2763 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2764 | ASSERT_TRUE(response); |
| 2765 | EXPECT_FALSE(response->auth_challenge); |
| 2766 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2767 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2768 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2770 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2771 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2772 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2773 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2774 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2775 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2779 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2780 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2781 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2782 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2783 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2786 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2787 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2788 | MockWrite("GET / HTTP/1.1\r\n" |
| 2789 | "Host: www.example.org\r\n" |
| 2790 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2792 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2793 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2794 | MockWrite("GET / HTTP/1.1\r\n" |
| 2795 | "Host: www.example.org\r\n" |
| 2796 | "Connection: keep-alive\r\n" |
| 2797 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2798 | }; |
| 2799 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | MockRead data_reads1[] = { |
| 2801 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2802 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2803 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | |
| 2805 | // Lastly, the server responds with the actual content. |
| 2806 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2807 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2808 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2809 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | }; |
| 2811 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2812 | // An incorrect reconnect would cause this to be read. |
| 2813 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2814 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2815 | }; |
| 2816 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2817 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2818 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2819 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2820 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2822 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2824 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2826 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2827 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | |
| 2830 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2831 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2834 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2835 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2837 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2839 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2841 | |
| 2842 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2845 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2846 | ASSERT_TRUE(response); |
| 2847 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2848 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2852 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2853 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2854 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2855 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2856 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2859 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2860 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2861 | MockWrite("GET / HTTP/1.1\r\n" |
| 2862 | "Host: www.example.org\r\n" |
| 2863 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2864 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2865 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2866 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2867 | MockWrite("GET / HTTP/1.1\r\n" |
| 2868 | "Host: www.example.org\r\n" |
| 2869 | "Connection: keep-alive\r\n" |
| 2870 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2871 | }; |
| 2872 | |
| 2873 | // Respond with 5 kb of response body. |
| 2874 | std::string large_body_string("Unauthorized"); |
| 2875 | large_body_string.append(5 * 1024, ' '); |
| 2876 | large_body_string.append("\r\n"); |
| 2877 | |
| 2878 | MockRead data_reads1[] = { |
| 2879 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2880 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2881 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2882 | // 5134 = 12 + 5 * 1024 + 2 |
| 2883 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2884 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2885 | |
| 2886 | // Lastly, the server responds with the actual content. |
| 2887 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2888 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2889 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2890 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2891 | }; |
| 2892 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2893 | // An incorrect reconnect would cause this to be read. |
| 2894 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2895 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2896 | }; |
| 2897 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2898 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2899 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2900 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2901 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2902 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2903 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2905 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2908 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | |
| 2911 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2912 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2914 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2915 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2916 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2917 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2918 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2920 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2922 | |
| 2923 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2924 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2926 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2927 | ASSERT_TRUE(response); |
| 2928 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2929 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2930 | } |
| 2931 | |
| 2932 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2933 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2934 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2935 | HttpRequestInfo request; |
| 2936 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2937 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2940 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2941 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2942 | MockWrite( |
| 2943 | "GET / HTTP/1.1\r\n" |
| 2944 | "Host: www.example.org\r\n" |
| 2945 | "Connection: keep-alive\r\n\r\n"), |
| 2946 | // This simulates the seemingly successful write to a closed connection |
| 2947 | // if the bug is not fixed. |
| 2948 | MockWrite( |
| 2949 | "GET / HTTP/1.1\r\n" |
| 2950 | "Host: www.example.org\r\n" |
| 2951 | "Connection: keep-alive\r\n" |
| 2952 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2953 | }; |
| 2954 | |
| 2955 | MockRead data_reads1[] = { |
| 2956 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2957 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2959 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2960 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2961 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2962 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2963 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2964 | }; |
| 2965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2966 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2967 | // be issuing -- the final header line contains the credentials. |
| 2968 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2969 | MockWrite( |
| 2970 | "GET / HTTP/1.1\r\n" |
| 2971 | "Host: www.example.org\r\n" |
| 2972 | "Connection: keep-alive\r\n" |
| 2973 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2974 | }; |
| 2975 | |
| 2976 | // Lastly, the server responds with the actual content. |
| 2977 | MockRead data_reads2[] = { |
| 2978 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2979 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2980 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2981 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2982 | }; |
| 2983 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2984 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2985 | data_writes1, arraysize(data_writes1)); |
| 2986 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2987 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2990 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2991 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2992 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2994 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2996 | |
| 2997 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2998 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3000 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3001 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3002 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3003 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3004 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3006 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3008 | |
| 3009 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3012 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3013 | ASSERT_TRUE(response); |
| 3014 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3015 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3016 | } |
| 3017 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3018 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3019 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3020 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3021 | HttpRequestInfo request; |
| 3022 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3023 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3024 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3025 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3026 | |
| 3027 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3028 | session_deps_.proxy_service = |
| 3029 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3030 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3031 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3033 | |
| 3034 | // Since we have proxy, should try to establish tunnel. |
| 3035 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3036 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3037 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3038 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3039 | }; |
| 3040 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3041 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3042 | // connection. |
| 3043 | MockRead data_reads1[] = { |
| 3044 | // No credentials. |
| 3045 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3046 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3047 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3048 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3049 | // Since the first connection couldn't be reused, need to establish another |
| 3050 | // once given credentials. |
| 3051 | MockWrite data_writes2[] = { |
| 3052 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3053 | // be issuing -- the final header line contains the credentials. |
| 3054 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3055 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3056 | "Proxy-Connection: keep-alive\r\n" |
| 3057 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3058 | |
| 3059 | MockWrite("GET / HTTP/1.1\r\n" |
| 3060 | "Host: www.example.org\r\n" |
| 3061 | "Connection: keep-alive\r\n\r\n"), |
| 3062 | }; |
| 3063 | |
| 3064 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3065 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3066 | |
| 3067 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3069 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3070 | MockRead(SYNCHRONOUS, "hello"), |
| 3071 | }; |
| 3072 | |
| 3073 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3074 | data_writes1, arraysize(data_writes1)); |
| 3075 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3076 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3077 | data_writes2, arraysize(data_writes2)); |
| 3078 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3079 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3081 | |
| 3082 | TestCompletionCallback callback1; |
| 3083 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3084 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3085 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3086 | |
| 3087 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3089 | |
| 3090 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3091 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3092 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3093 | log.GetEntries(&entries); |
| 3094 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3095 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3096 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3097 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3098 | entries, pos, |
| 3099 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3100 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3101 | |
| 3102 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3103 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3104 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3105 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3106 | EXPECT_EQ(407, response->headers->response_code()); |
| 3107 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3108 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3109 | |
| 3110 | LoadTimingInfo load_timing_info; |
| 3111 | // CONNECT requests and responses are handled at the connect job level, so |
| 3112 | // the transaction does not yet have a connection. |
| 3113 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3114 | |
| 3115 | TestCompletionCallback callback2; |
| 3116 | |
| 3117 | rv = |
| 3118 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3120 | |
| 3121 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3122 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3123 | |
| 3124 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3125 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3126 | |
| 3127 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3128 | EXPECT_EQ(200, response->headers->response_code()); |
| 3129 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3130 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3131 | |
| 3132 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3133 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3134 | |
| 3135 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3136 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3137 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3138 | |
| 3139 | trans.reset(); |
| 3140 | session->CloseAllConnections(); |
| 3141 | } |
| 3142 | |
| 3143 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3144 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3145 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3146 | HttpRequestInfo request; |
| 3147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3148 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3149 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3150 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3151 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3152 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3153 | session_deps_.proxy_service = |
| 3154 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3155 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3156 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3157 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3158 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3159 | // Since we have proxy, should try to establish tunnel. |
| 3160 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3161 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3162 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3163 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3164 | }; |
| 3165 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3166 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3167 | // connection. |
| 3168 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3169 | // No credentials. |
| 3170 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3171 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3172 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3173 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3174 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3175 | MockWrite data_writes2[] = { |
| 3176 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3177 | // be issuing -- the final header line contains the credentials. |
| 3178 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3179 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3180 | "Proxy-Connection: keep-alive\r\n" |
| 3181 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3182 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3183 | MockWrite("GET / HTTP/1.1\r\n" |
| 3184 | "Host: www.example.org\r\n" |
| 3185 | "Connection: keep-alive\r\n\r\n"), |
| 3186 | }; |
| 3187 | |
| 3188 | MockRead data_reads2[] = { |
| 3189 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3190 | |
| 3191 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3192 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3193 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3194 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3195 | }; |
| 3196 | |
| 3197 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3198 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3199 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3200 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3201 | data_writes2, arraysize(data_writes2)); |
| 3202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3203 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3206 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3207 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3208 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3209 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3211 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3213 | |
| 3214 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3215 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3216 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3217 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3218 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3219 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3220 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3221 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3222 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3223 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3224 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3225 | |
| 3226 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3227 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3228 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3229 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3230 | EXPECT_EQ(407, response->headers->response_code()); |
| 3231 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3232 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3233 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3234 | LoadTimingInfo load_timing_info; |
| 3235 | // CONNECT requests and responses are handled at the connect job level, so |
| 3236 | // the transaction does not yet have a connection. |
| 3237 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3239 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3241 | rv = trans->RestartWithAuth( |
| 3242 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3244 | |
| 3245 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3246 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3247 | |
| 3248 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3249 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3250 | |
| 3251 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3252 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3253 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3254 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3255 | |
| 3256 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3257 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3258 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3259 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3260 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3261 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3262 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3263 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3264 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3265 | } |
| 3266 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3267 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3268 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3269 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3270 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3271 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3272 | // reused. See http://crbug.com/544255. |
| 3273 | for (int i = 0; i < 2; ++i) { |
| 3274 | HttpRequestInfo request; |
| 3275 | request.method = "GET"; |
| 3276 | request.url = GURL("https://www.example.org/"); |
| 3277 | // Ensure that proxy authentication is attempted even |
| 3278 | // when the no authentication data flag is set. |
| 3279 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3281 | // Configure against proxy server "myproxy:70". |
| 3282 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3283 | BoundTestNetLog log; |
| 3284 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3288 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3289 | // Since we have proxy, should try to establish tunnel. |
| 3290 | MockWrite data_writes1[] = { |
| 3291 | MockWrite(ASYNC, 0, |
| 3292 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3293 | "Host: www.example.org:443\r\n" |
| 3294 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3296 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3297 | // be issuing -- the final header line contains the credentials. |
| 3298 | MockWrite(ASYNC, 3, |
| 3299 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3300 | "Host: www.example.org:443\r\n" |
| 3301 | "Proxy-Connection: keep-alive\r\n" |
| 3302 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3303 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3304 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3305 | // The proxy responds to the connect with a 407, using a persistent |
| 3306 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3307 | MockRead data_reads1[] = { |
| 3308 | // No credentials. |
| 3309 | MockRead(ASYNC, 1, |
| 3310 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3311 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3312 | "Proxy-Connection: keep-alive\r\n" |
| 3313 | "Content-Length: 10\r\n\r\n"), |
| 3314 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3315 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3316 | // Wrong credentials (wrong password). |
| 3317 | MockRead(ASYNC, 4, |
| 3318 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3319 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3320 | "Proxy-Connection: keep-alive\r\n" |
| 3321 | "Content-Length: 10\r\n\r\n"), |
| 3322 | // No response body because the test stops reading here. |
| 3323 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3324 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3325 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3326 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3327 | arraysize(data_writes1)); |
| 3328 | data1.set_busy_before_sync_reads(true); |
| 3329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3331 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3333 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3334 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3335 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3336 | TestNetLogEntry::List entries; |
| 3337 | log.GetEntries(&entries); |
| 3338 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3339 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3340 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3341 | ExpectLogContainsSomewhere( |
| 3342 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3343 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3344 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3346 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3347 | ASSERT_TRUE(response); |
| 3348 | ASSERT_TRUE(response->headers); |
| 3349 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3350 | EXPECT_EQ(407, response->headers->response_code()); |
| 3351 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3352 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3353 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3355 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3357 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3358 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3359 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3360 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3361 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3362 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3363 | ASSERT_TRUE(response); |
| 3364 | ASSERT_TRUE(response->headers); |
| 3365 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3366 | EXPECT_EQ(407, response->headers->response_code()); |
| 3367 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3368 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3369 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3372 | // out of scope. |
| 3373 | session->CloseAllConnections(); |
| 3374 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3378 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3379 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3380 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3381 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3382 | // reused. See http://crbug.com/544255. |
| 3383 | for (int i = 0; i < 2; ++i) { |
| 3384 | HttpRequestInfo request; |
| 3385 | request.method = "GET"; |
| 3386 | request.url = GURL("https://www.example.org/"); |
| 3387 | // Ensure that proxy authentication is attempted even |
| 3388 | // when the no authentication data flag is set. |
| 3389 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3390 | |
| 3391 | // Configure against proxy server "myproxy:70". |
| 3392 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3393 | BoundTestNetLog log; |
| 3394 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3396 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3398 | |
| 3399 | // Since we have proxy, should try to establish tunnel. |
| 3400 | MockWrite data_writes1[] = { |
| 3401 | MockWrite(ASYNC, 0, |
| 3402 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3403 | "Host: www.example.org:443\r\n" |
| 3404 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3406 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3407 | // be issuing -- the final header line contains the credentials. |
| 3408 | MockWrite(ASYNC, 3, |
| 3409 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3410 | "Host: www.example.org:443\r\n" |
| 3411 | "Proxy-Connection: keep-alive\r\n" |
| 3412 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3413 | }; |
| 3414 | |
| 3415 | // The proxy responds to the connect with a 407, using a persistent |
| 3416 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3417 | MockRead data_reads1[] = { |
| 3418 | // No credentials. |
| 3419 | MockRead(ASYNC, 1, |
| 3420 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3421 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3422 | "Content-Length: 10\r\n\r\n"), |
| 3423 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3424 | |
| 3425 | // Wrong credentials (wrong password). |
| 3426 | MockRead(ASYNC, 4, |
| 3427 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3428 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3429 | "Content-Length: 10\r\n\r\n"), |
| 3430 | // No response body because the test stops reading here. |
| 3431 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3432 | }; |
| 3433 | |
| 3434 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3435 | arraysize(data_writes1)); |
| 3436 | data1.set_busy_before_sync_reads(true); |
| 3437 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3438 | |
| 3439 | TestCompletionCallback callback1; |
| 3440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3441 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3442 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3443 | |
| 3444 | TestNetLogEntry::List entries; |
| 3445 | log.GetEntries(&entries); |
| 3446 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3447 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3448 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3449 | ExpectLogContainsSomewhere( |
| 3450 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3451 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3452 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3453 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3454 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3455 | ASSERT_TRUE(response); |
| 3456 | ASSERT_TRUE(response->headers); |
| 3457 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3458 | EXPECT_EQ(407, response->headers->response_code()); |
| 3459 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3460 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3461 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3462 | |
| 3463 | TestCompletionCallback callback2; |
| 3464 | |
| 3465 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3466 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3467 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3468 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3469 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3470 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | ASSERT_TRUE(response); |
| 3472 | ASSERT_TRUE(response->headers); |
| 3473 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3474 | EXPECT_EQ(407, response->headers->response_code()); |
| 3475 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3476 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3477 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3478 | |
| 3479 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3480 | // out of scope. |
| 3481 | session->CloseAllConnections(); |
| 3482 | } |
| 3483 | } |
| 3484 | |
| 3485 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3486 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3487 | // the case the server sends extra data on the original socket, so it can't be |
| 3488 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3489 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3490 | HttpRequestInfo request; |
| 3491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3492 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3493 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3494 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3495 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3496 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3497 | session_deps_.proxy_service = |
| 3498 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3499 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3500 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3501 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3502 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3503 | // Since we have proxy, should try to establish tunnel. |
| 3504 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3505 | MockWrite(ASYNC, 0, |
| 3506 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3507 | "Host: www.example.org:443\r\n" |
| 3508 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3509 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3510 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3511 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3512 | // extra data, so the socket cannot be reused. |
| 3513 | MockRead data_reads1[] = { |
| 3514 | // No credentials. |
| 3515 | MockRead(ASYNC, 1, |
| 3516 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3517 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3518 | "Content-Length: 10\r\n\r\n"), |
| 3519 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3520 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3521 | }; |
| 3522 | |
| 3523 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3524 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3525 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3526 | MockWrite(ASYNC, 0, |
| 3527 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3528 | "Host: www.example.org:443\r\n" |
| 3529 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3530 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3531 | |
| 3532 | MockWrite(ASYNC, 2, |
| 3533 | "GET / HTTP/1.1\r\n" |
| 3534 | "Host: www.example.org\r\n" |
| 3535 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3536 | }; |
| 3537 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | MockRead data_reads2[] = { |
| 3539 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3540 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3541 | MockRead(ASYNC, 3, |
| 3542 | "HTTP/1.1 200 OK\r\n" |
| 3543 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3544 | "Content-Length: 5\r\n\r\n"), |
| 3545 | // No response body because the test stops reading here. |
| 3546 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3547 | }; |
| 3548 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3549 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3550 | arraysize(data_writes1)); |
| 3551 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3552 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3553 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3554 | arraysize(data_writes2)); |
| 3555 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3556 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3559 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3560 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3561 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3562 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3563 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3564 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3565 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3567 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3568 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3569 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3570 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3571 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3572 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3573 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3574 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3575 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3576 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3577 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3578 | ASSERT_TRUE(response); |
| 3579 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3580 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3581 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3582 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3583 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3584 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | LoadTimingInfo load_timing_info; |
| 3586 | // CONNECT requests and responses are handled at the connect job level, so |
| 3587 | // the transaction does not yet have a connection. |
| 3588 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3589 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3590 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3591 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | rv = |
| 3593 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3594 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3595 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3596 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3597 | EXPECT_EQ(200, response->headers->response_code()); |
| 3598 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3599 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3600 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3601 | // The password prompt info should not be set. |
| 3602 | EXPECT_FALSE(response->auth_challenge); |
| 3603 | |
| 3604 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3605 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3606 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3607 | |
| 3608 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3609 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3610 | } |
| 3611 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3612 | // Test the case a proxy closes a socket while the challenge body is being |
| 3613 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3614 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3615 | HttpRequestInfo request; |
| 3616 | request.method = "GET"; |
| 3617 | request.url = GURL("https://www.example.org/"); |
| 3618 | // Ensure that proxy authentication is attempted even |
| 3619 | // when the no authentication data flag is set. |
| 3620 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3621 | |
| 3622 | // Configure against proxy server "myproxy:70". |
| 3623 | session_deps_.proxy_service = ProxyService::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". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3710 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3711 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3715 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3716 | // Since we have proxy, should try to establish tunnel. |
| 3717 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3718 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3719 | "Host: www.example.org:443\r\n" |
| 3720 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3721 | }; |
| 3722 | |
| 3723 | // The proxy responds to the connect with a 407. |
| 3724 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3725 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3726 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3727 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3728 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3729 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3730 | }; |
| 3731 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3732 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3733 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3734 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3735 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3736 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3740 | |
| 3741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3742 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3744 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3745 | ASSERT_TRUE(response); |
| 3746 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3747 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3748 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3749 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3750 | |
| 3751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3752 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3753 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3754 | |
| 3755 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3756 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3757 | } |
| 3758 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3759 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3760 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3761 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3762 | HttpRequestInfo request; |
| 3763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3764 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3765 | |
| 3766 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3767 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3768 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | |
| 3773 | // Since we have proxy, should try to establish tunnel. |
| 3774 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3775 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3776 | "Host: www.example.org:443\r\n" |
| 3777 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3778 | }; |
| 3779 | |
| 3780 | // The proxy responds to the connect with a 407. |
| 3781 | MockRead data_reads[] = { |
| 3782 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3783 | MockRead("X-Foo: bar\r\n"), |
| 3784 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3785 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3786 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3787 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3788 | }; |
| 3789 | |
| 3790 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3791 | arraysize(data_writes)); |
| 3792 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3793 | |
| 3794 | TestCompletionCallback callback; |
| 3795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3796 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3798 | |
| 3799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3800 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3802 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3803 | ASSERT_TRUE(response); |
| 3804 | ASSERT_TRUE(response->headers); |
| 3805 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3806 | EXPECT_EQ(407, response->headers->response_code()); |
| 3807 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3808 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3809 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3810 | |
| 3811 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3812 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3813 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3814 | |
| 3815 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3816 | session->CloseAllConnections(); |
| 3817 | } |
| 3818 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3819 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3820 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3821 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3822 | HttpRequestInfo request; |
| 3823 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3824 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3825 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3826 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3829 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3830 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3831 | MockWrite( |
| 3832 | "GET / HTTP/1.1\r\n" |
| 3833 | "Host: www.example.org\r\n" |
| 3834 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3835 | }; |
| 3836 | |
| 3837 | MockRead data_reads1[] = { |
| 3838 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3839 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3840 | // Large content-length -- won't matter, as connection will be reset. |
| 3841 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3842 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3843 | }; |
| 3844 | |
| 3845 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3846 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3847 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3848 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3849 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3850 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3851 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3853 | |
| 3854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3855 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3856 | } |
| 3857 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3858 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3859 | // through a non-authenticating proxy. The request should fail with |
| 3860 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3861 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3862 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3863 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3864 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3865 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3866 | HttpRequestInfo request; |
| 3867 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3868 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3869 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3870 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3871 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3872 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3874 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3875 | // Since we have proxy, should try to establish tunnel. |
| 3876 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3878 | "Host: www.example.org:443\r\n" |
| 3879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3880 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3881 | MockWrite("GET / HTTP/1.1\r\n" |
| 3882 | "Host: www.example.org\r\n" |
| 3883 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3884 | }; |
| 3885 | |
| 3886 | MockRead data_reads1[] = { |
| 3887 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3888 | |
| 3889 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3890 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3891 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3893 | }; |
| 3894 | |
| 3895 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3896 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3897 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3898 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3901 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3905 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3907 | |
| 3908 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3909 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3910 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3911 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3912 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3913 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3914 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3915 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3916 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3917 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3918 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3919 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3920 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3921 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3922 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3923 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3924 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3925 | HttpRequestInfo request; |
| 3926 | request.method = "GET"; |
| 3927 | request.url = GURL("https://www.example.org/"); |
| 3928 | |
| 3929 | // Configure against proxy server "myproxy:70". |
| 3930 | session_deps_.proxy_service = |
| 3931 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3932 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3933 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3934 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3935 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3936 | mock_handler->set_allows_default_credentials(true); |
| 3937 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3938 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3939 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | |
| 3941 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3942 | NetLog net_log; |
| 3943 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3944 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3945 | |
| 3946 | // Since we have proxy, should try to establish tunnel. |
| 3947 | MockWrite data_writes1[] = { |
| 3948 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3949 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3950 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3951 | }; |
| 3952 | |
| 3953 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3954 | // connection. |
| 3955 | MockRead data_reads1[] = { |
| 3956 | // No credentials. |
| 3957 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3958 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3959 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3960 | }; |
| 3961 | |
| 3962 | // Since the first connection couldn't be reused, need to establish another |
| 3963 | // once given credentials. |
| 3964 | MockWrite data_writes2[] = { |
| 3965 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3966 | // be issuing -- the final header line contains the credentials. |
| 3967 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3968 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3969 | "Proxy-Connection: keep-alive\r\n" |
| 3970 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3971 | |
| 3972 | MockWrite("GET / HTTP/1.1\r\n" |
| 3973 | "Host: www.example.org\r\n" |
| 3974 | "Connection: keep-alive\r\n\r\n"), |
| 3975 | }; |
| 3976 | |
| 3977 | MockRead data_reads2[] = { |
| 3978 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3979 | |
| 3980 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3981 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3982 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3983 | MockRead(SYNCHRONOUS, "hello"), |
| 3984 | }; |
| 3985 | |
| 3986 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3987 | data_writes1, arraysize(data_writes1)); |
| 3988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3989 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3990 | data_writes2, arraysize(data_writes2)); |
| 3991 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3992 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3994 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3995 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3996 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3997 | |
| 3998 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3999 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4000 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4001 | |
| 4002 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4003 | ASSERT_TRUE(response); |
| 4004 | ASSERT_TRUE(response->headers); |
| 4005 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4006 | EXPECT_EQ(407, response->headers->response_code()); |
| 4007 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4008 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4009 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4010 | |
| 4011 | LoadTimingInfo load_timing_info; |
| 4012 | // CONNECT requests and responses are handled at the connect job level, so |
| 4013 | // the transaction does not yet have a connection. |
| 4014 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4015 | |
| 4016 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4017 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4018 | response = trans->GetResponseInfo(); |
| 4019 | ASSERT_TRUE(response); |
| 4020 | ASSERT_TRUE(response->headers); |
| 4021 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4022 | EXPECT_EQ(200, response->headers->response_code()); |
| 4023 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4024 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4025 | |
| 4026 | // The password prompt info should not be set. |
| 4027 | EXPECT_FALSE(response->auth_challenge); |
| 4028 | |
| 4029 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4030 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4031 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4032 | |
| 4033 | trans.reset(); |
| 4034 | session->CloseAllConnections(); |
| 4035 | } |
| 4036 | |
| 4037 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4038 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4039 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4040 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4041 | HttpRequestInfo request; |
| 4042 | request.method = "GET"; |
| 4043 | request.url = GURL("https://www.example.org/"); |
| 4044 | |
| 4045 | // Configure against proxy server "myproxy:70". |
| 4046 | session_deps_.proxy_service = |
| 4047 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4048 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4049 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4050 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4051 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4052 | mock_handler->set_allows_default_credentials(true); |
| 4053 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4054 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4055 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4056 | |
| 4057 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4058 | NetLog net_log; |
| 4059 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4060 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4061 | |
| 4062 | // Should try to establish tunnel. |
| 4063 | MockWrite data_writes1[] = { |
| 4064 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4065 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4066 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4067 | |
| 4068 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4069 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4070 | "Proxy-Connection: keep-alive\r\n" |
| 4071 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4072 | }; |
| 4073 | |
| 4074 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4075 | // connection. |
| 4076 | MockRead data_reads1[] = { |
| 4077 | // No credentials. |
| 4078 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4079 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4080 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4081 | }; |
| 4082 | |
| 4083 | // Since the first connection was closed, need to establish another once given |
| 4084 | // credentials. |
| 4085 | MockWrite data_writes2[] = { |
| 4086 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4087 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4088 | "Proxy-Connection: keep-alive\r\n" |
| 4089 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4090 | |
| 4091 | MockWrite("GET / HTTP/1.1\r\n" |
| 4092 | "Host: www.example.org\r\n" |
| 4093 | "Connection: keep-alive\r\n\r\n"), |
| 4094 | }; |
| 4095 | |
| 4096 | MockRead data_reads2[] = { |
| 4097 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4098 | |
| 4099 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4100 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4101 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4102 | MockRead(SYNCHRONOUS, "hello"), |
| 4103 | }; |
| 4104 | |
| 4105 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4106 | data_writes1, arraysize(data_writes1)); |
| 4107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4108 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4109 | data_writes2, arraysize(data_writes2)); |
| 4110 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4111 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4113 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4114 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4115 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4116 | |
| 4117 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4118 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4119 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4120 | |
| 4121 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4122 | ASSERT_TRUE(response); |
| 4123 | ASSERT_TRUE(response->headers); |
| 4124 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4125 | EXPECT_EQ(407, response->headers->response_code()); |
| 4126 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4127 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4128 | EXPECT_FALSE(response->auth_challenge); |
| 4129 | |
| 4130 | LoadTimingInfo load_timing_info; |
| 4131 | // CONNECT requests and responses are handled at the connect job level, so |
| 4132 | // the transaction does not yet have a connection. |
| 4133 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4134 | |
| 4135 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4136 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4137 | |
| 4138 | response = trans->GetResponseInfo(); |
| 4139 | ASSERT_TRUE(response); |
| 4140 | ASSERT_TRUE(response->headers); |
| 4141 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4142 | EXPECT_EQ(200, response->headers->response_code()); |
| 4143 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4144 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4145 | |
| 4146 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4147 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4148 | |
| 4149 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4150 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4151 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4152 | |
| 4153 | trans.reset(); |
| 4154 | session->CloseAllConnections(); |
| 4155 | } |
| 4156 | |
| 4157 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4158 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4159 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4160 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4161 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4162 | HttpRequestInfo request; |
| 4163 | request.method = "GET"; |
| 4164 | request.url = GURL("https://www.example.org/"); |
| 4165 | |
| 4166 | // Configure against proxy server "myproxy:70". |
| 4167 | session_deps_.proxy_service = |
| 4168 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4169 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4170 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4171 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4172 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | mock_handler->set_allows_default_credentials(true); |
| 4174 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4175 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4176 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4177 | |
| 4178 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4179 | NetLog net_log; |
| 4180 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4181 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | |
| 4183 | // Should try to establish tunnel. |
| 4184 | MockWrite data_writes1[] = { |
| 4185 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4186 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4188 | |
| 4189 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4190 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4191 | "Proxy-Connection: keep-alive\r\n" |
| 4192 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4193 | }; |
| 4194 | |
| 4195 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4196 | // second request is sent. |
| 4197 | MockRead data_reads1[] = { |
| 4198 | // No credentials. |
| 4199 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4200 | MockRead("Content-Length: 0\r\n"), |
| 4201 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4202 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4203 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4204 | }; |
| 4205 | |
| 4206 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4207 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4208 | // request. |
| 4209 | MockWrite data_writes2[] = { |
| 4210 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4211 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4213 | }; |
| 4214 | |
| 4215 | // The proxy, having had more than enough of us, just hangs up. |
| 4216 | MockRead data_reads2[] = { |
| 4217 | // No credentials. |
| 4218 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4219 | }; |
| 4220 | |
| 4221 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4222 | data_writes1, arraysize(data_writes1)); |
| 4223 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4224 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4225 | data_writes2, arraysize(data_writes2)); |
| 4226 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4227 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4228 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4229 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4230 | |
| 4231 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4232 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4233 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4234 | |
| 4235 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4236 | ASSERT_TRUE(response); |
| 4237 | ASSERT_TRUE(response->headers); |
| 4238 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4239 | EXPECT_EQ(407, response->headers->response_code()); |
| 4240 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4241 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4242 | EXPECT_FALSE(response->auth_challenge); |
| 4243 | |
| 4244 | LoadTimingInfo load_timing_info; |
| 4245 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4246 | |
| 4247 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4248 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4249 | |
| 4250 | trans.reset(); |
| 4251 | session->CloseAllConnections(); |
| 4252 | } |
| 4253 | |
| 4254 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4255 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4256 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4257 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4258 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4259 | HttpRequestInfo request; |
| 4260 | request.method = "GET"; |
| 4261 | request.url = GURL("https://www.example.org/"); |
| 4262 | |
| 4263 | // Configure against proxy server "myproxy:70". |
| 4264 | session_deps_.proxy_service = |
| 4265 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4266 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4267 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4268 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4269 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4270 | mock_handler->set_allows_default_credentials(true); |
| 4271 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4272 | HttpAuth::AUTH_PROXY); |
| 4273 | // Add another handler for the second challenge. It supports default |
| 4274 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4275 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4276 | mock_handler->set_allows_default_credentials(true); |
| 4277 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4278 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4279 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | |
| 4281 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4282 | NetLog net_log; |
| 4283 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4284 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4285 | |
| 4286 | // Should try to establish tunnel. |
| 4287 | MockWrite data_writes1[] = { |
| 4288 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4289 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4290 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4291 | }; |
| 4292 | |
| 4293 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4294 | // connection. |
| 4295 | MockRead data_reads1[] = { |
| 4296 | // No credentials. |
| 4297 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4298 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4299 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4300 | }; |
| 4301 | |
| 4302 | // Since the first connection was closed, need to establish another once given |
| 4303 | // credentials. |
| 4304 | MockWrite data_writes2[] = { |
| 4305 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4306 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4307 | "Proxy-Connection: keep-alive\r\n" |
| 4308 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4309 | }; |
| 4310 | |
| 4311 | MockRead data_reads2[] = { |
| 4312 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4313 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4314 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4315 | }; |
| 4316 | |
| 4317 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4318 | data_writes1, arraysize(data_writes1)); |
| 4319 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4320 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4321 | data_writes2, arraysize(data_writes2)); |
| 4322 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4323 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4325 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4326 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4327 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4328 | |
| 4329 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4330 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4331 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4332 | |
| 4333 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4334 | ASSERT_TRUE(response); |
| 4335 | ASSERT_TRUE(response->headers); |
| 4336 | EXPECT_EQ(407, response->headers->response_code()); |
| 4337 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4338 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4339 | EXPECT_FALSE(response->auth_challenge); |
| 4340 | |
| 4341 | LoadTimingInfo load_timing_info; |
| 4342 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4343 | |
| 4344 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4345 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4346 | response = trans->GetResponseInfo(); |
| 4347 | ASSERT_TRUE(response); |
| 4348 | ASSERT_TRUE(response->headers); |
| 4349 | EXPECT_EQ(407, response->headers->response_code()); |
| 4350 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4351 | EXPECT_TRUE(response->auth_challenge); |
| 4352 | |
| 4353 | trans.reset(); |
| 4354 | session->CloseAllConnections(); |
| 4355 | } |
| 4356 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4357 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4358 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4359 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4360 | // authentication handshake can continue with the same scheme but with a |
| 4361 | // different identity. |
| 4362 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4363 | HttpRequestInfo request; |
| 4364 | request.method = "GET"; |
| 4365 | request.url = GURL("http://www.example.org/"); |
| 4366 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4367 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4368 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4369 | |
| 4370 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4371 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4372 | mock_handler->set_allows_default_credentials(true); |
| 4373 | mock_handler->set_allows_explicit_credentials(true); |
| 4374 | mock_handler->set_connection_based(true); |
| 4375 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4376 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4377 | HttpAuth::AUTH_SERVER); |
| 4378 | |
| 4379 | // Add another handler for the second challenge. It supports default |
| 4380 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4381 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4382 | mock_handler->set_allows_default_credentials(true); |
| 4383 | mock_handler->set_allows_explicit_credentials(true); |
| 4384 | mock_handler->set_connection_based(true); |
| 4385 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4386 | HttpAuth::AUTH_SERVER); |
| 4387 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4388 | |
| 4389 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4390 | |
| 4391 | MockWrite data_writes1[] = { |
| 4392 | MockWrite("GET / HTTP/1.1\r\n" |
| 4393 | "Host: www.example.org\r\n" |
| 4394 | "Connection: keep-alive\r\n\r\n"), |
| 4395 | }; |
| 4396 | |
| 4397 | MockRead data_reads1[] = { |
| 4398 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4399 | "WWW-Authenticate: Mock\r\n" |
| 4400 | "Connection: keep-alive\r\n\r\n"), |
| 4401 | }; |
| 4402 | |
| 4403 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4404 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4405 | // transaction procceds without an authorization header. |
| 4406 | MockWrite data_writes2[] = { |
| 4407 | MockWrite("GET / HTTP/1.1\r\n" |
| 4408 | "Host: www.example.org\r\n" |
| 4409 | "Connection: keep-alive\r\n\r\n"), |
| 4410 | }; |
| 4411 | |
| 4412 | MockRead data_reads2[] = { |
| 4413 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4414 | "WWW-Authenticate: Mock\r\n" |
| 4415 | "Connection: keep-alive\r\n\r\n"), |
| 4416 | }; |
| 4417 | |
| 4418 | MockWrite data_writes3[] = { |
| 4419 | MockWrite("GET / HTTP/1.1\r\n" |
| 4420 | "Host: www.example.org\r\n" |
| 4421 | "Connection: keep-alive\r\n" |
| 4422 | "Authorization: auth_token\r\n\r\n"), |
| 4423 | }; |
| 4424 | |
| 4425 | MockRead data_reads3[] = { |
| 4426 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4427 | "Content-Length: 5\r\n" |
| 4428 | "Content-Type: text/plain\r\n" |
| 4429 | "Connection: keep-alive\r\n\r\n" |
| 4430 | "Hello"), |
| 4431 | }; |
| 4432 | |
| 4433 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4434 | data_writes1, arraysize(data_writes1)); |
| 4435 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4436 | |
| 4437 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4438 | data_writes2, arraysize(data_writes2)); |
| 4439 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4440 | |
| 4441 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4442 | data_writes3, arraysize(data_writes3)); |
| 4443 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4444 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4445 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4446 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4447 | |
| 4448 | TestCompletionCallback callback; |
| 4449 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4450 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4451 | |
| 4452 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4453 | ASSERT_TRUE(response); |
| 4454 | ASSERT_TRUE(response->headers); |
| 4455 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4456 | |
| 4457 | // The following three tests assert that an authentication challenge was |
| 4458 | // received and that the stack is ready to respond to the challenge using |
| 4459 | // ambient credentials. |
| 4460 | EXPECT_EQ(401, response->headers->response_code()); |
| 4461 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4462 | EXPECT_FALSE(response->auth_challenge); |
| 4463 | |
| 4464 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4465 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4466 | response = trans->GetResponseInfo(); |
| 4467 | ASSERT_TRUE(response); |
| 4468 | ASSERT_TRUE(response->headers); |
| 4469 | |
| 4470 | // The following three tests assert that an authentication challenge was |
| 4471 | // received and that the stack needs explicit credentials before it is ready |
| 4472 | // to respond to the challenge. |
| 4473 | EXPECT_EQ(401, response->headers->response_code()); |
| 4474 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4475 | EXPECT_TRUE(response->auth_challenge); |
| 4476 | |
| 4477 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4478 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4479 | response = trans->GetResponseInfo(); |
| 4480 | ASSERT_TRUE(response); |
| 4481 | ASSERT_TRUE(response->headers); |
| 4482 | EXPECT_EQ(200, response->headers->response_code()); |
| 4483 | |
| 4484 | trans.reset(); |
| 4485 | session->CloseAllConnections(); |
| 4486 | } |
| 4487 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame^] | 4488 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4489 | // schemes, based on the path of the URL being requests. |
| 4490 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4491 | public: |
| 4492 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4493 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4494 | |
| 4495 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4496 | |
| 4497 | static HostPortPair ProxyHostPortPair() { |
| 4498 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4499 | } |
| 4500 | |
| 4501 | // ProxyResolver implementation. |
| 4502 | int GetProxyForURL(const GURL& url, |
| 4503 | ProxyInfo* results, |
| 4504 | const CompletionCallback& callback, |
| 4505 | std::unique_ptr<Request>* request, |
| 4506 | const NetLogWithSource& /*net_log*/) override { |
| 4507 | *results = ProxyInfo(); |
| 4508 | if (url.path() == "/socks4") { |
| 4509 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4510 | return OK; |
| 4511 | } |
| 4512 | if (url.path() == "/socks5") { |
| 4513 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4514 | return OK; |
| 4515 | } |
| 4516 | if (url.path() == "/http") { |
| 4517 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4518 | return OK; |
| 4519 | } |
| 4520 | if (url.path() == "/https") { |
| 4521 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4522 | return OK; |
| 4523 | } |
| 4524 | NOTREACHED(); |
| 4525 | return ERR_NOT_IMPLEMENTED; |
| 4526 | } |
| 4527 | |
| 4528 | private: |
| 4529 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4530 | }; |
| 4531 | |
| 4532 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4533 | : public ProxyResolverFactory { |
| 4534 | public: |
| 4535 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4536 | : ProxyResolverFactory(false) {} |
| 4537 | |
| 4538 | int CreateProxyResolver( |
| 4539 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 4540 | std::unique_ptr<ProxyResolver>* resolver, |
| 4541 | const CompletionCallback& callback, |
| 4542 | std::unique_ptr<Request>* request) override { |
| 4543 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4544 | return OK; |
| 4545 | } |
| 4546 | |
| 4547 | private: |
| 4548 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4549 | }; |
| 4550 | |
| 4551 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4552 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4553 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4554 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4555 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
| 4556 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 4557 | std::make_unique<ProxyConfigServiceFixed>( |
| 4558 | ProxyConfig::CreateAutoDetect()), |
| 4559 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4560 | nullptr); |
| 4561 | |
| 4562 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4563 | |
| 4564 | MockWrite socks_writes[] = { |
| 4565 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4566 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4567 | MockWrite(SYNCHRONOUS, |
| 4568 | "GET /socks4 HTTP/1.1\r\n" |
| 4569 | "Host: test\r\n" |
| 4570 | "Connection: keep-alive\r\n\r\n"), |
| 4571 | }; |
| 4572 | MockRead socks_reads[] = { |
| 4573 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4574 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4575 | "Connection: keep-alive\r\n" |
| 4576 | "Content-Length: 15\r\n\r\n" |
| 4577 | "SOCKS4 Response"), |
| 4578 | }; |
| 4579 | StaticSocketDataProvider socks_data(socks_reads, arraysize(socks_reads), |
| 4580 | socks_writes, arraysize(socks_writes)); |
| 4581 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4582 | |
| 4583 | const char kSOCKS5Request[] = { |
| 4584 | 0x05, // Version |
| 4585 | 0x01, // Command (CONNECT) |
| 4586 | 0x00, // Reserved |
| 4587 | 0x03, // Address type (DOMAINNAME) |
| 4588 | 0x04, // Length of domain (4) |
| 4589 | 't', 'e', 's', 't', // Domain string |
| 4590 | 0x00, 0x50, // 16-bit port (80) |
| 4591 | }; |
| 4592 | MockWrite socks5_writes[] = { |
| 4593 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4594 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4595 | MockWrite(SYNCHRONOUS, |
| 4596 | "GET /socks5 HTTP/1.1\r\n" |
| 4597 | "Host: test\r\n" |
| 4598 | "Connection: keep-alive\r\n\r\n"), |
| 4599 | }; |
| 4600 | MockRead socks5_reads[] = { |
| 4601 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4602 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4603 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4604 | "Connection: keep-alive\r\n" |
| 4605 | "Content-Length: 15\r\n\r\n" |
| 4606 | "SOCKS5 Response"), |
| 4607 | }; |
| 4608 | StaticSocketDataProvider socks5_data(socks5_reads, arraysize(socks5_reads), |
| 4609 | socks5_writes, arraysize(socks5_writes)); |
| 4610 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4611 | |
| 4612 | MockWrite http_writes[] = { |
| 4613 | MockWrite(SYNCHRONOUS, |
| 4614 | "GET http://test/http HTTP/1.1\r\n" |
| 4615 | "Host: test\r\n" |
| 4616 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4617 | }; |
| 4618 | MockRead http_reads[] = { |
| 4619 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4620 | "Proxy-Connection: keep-alive\r\n" |
| 4621 | "Content-Length: 13\r\n\r\n" |
| 4622 | "HTTP Response"), |
| 4623 | }; |
| 4624 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 4625 | http_writes, arraysize(http_writes)); |
| 4626 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4627 | |
| 4628 | MockWrite https_writes[] = { |
| 4629 | MockWrite(SYNCHRONOUS, |
| 4630 | "GET http://test/https HTTP/1.1\r\n" |
| 4631 | "Host: test\r\n" |
| 4632 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4633 | }; |
| 4634 | MockRead https_reads[] = { |
| 4635 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4636 | "Proxy-Connection: keep-alive\r\n" |
| 4637 | "Content-Length: 14\r\n\r\n" |
| 4638 | "HTTPS Response"), |
| 4639 | }; |
| 4640 | StaticSocketDataProvider https_data(https_reads, arraysize(https_reads), |
| 4641 | https_writes, arraysize(https_writes)); |
| 4642 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4643 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4644 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4645 | |
| 4646 | struct TestCase { |
| 4647 | GURL url; |
| 4648 | std::string expected_response; |
| 4649 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4650 | // after the test. |
| 4651 | int expected_idle_socks_sockets; |
| 4652 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4653 | // the test. |
| 4654 | int expected_idle_http_sockets; |
| 4655 | } const kTestCases[] = { |
| 4656 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4657 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4658 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4659 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4660 | }; |
| 4661 | |
| 4662 | for (const auto& test_case : kTestCases) { |
| 4663 | HttpRequestInfo request; |
| 4664 | request.method = "GET"; |
| 4665 | request.url = test_case.url; |
| 4666 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4667 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4668 | session.get()); |
| 4669 | TestCompletionCallback callback; |
| 4670 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4671 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4672 | |
| 4673 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4674 | ASSERT_TRUE(response); |
| 4675 | ASSERT_TRUE(response->headers); |
| 4676 | EXPECT_EQ(200, response->headers->response_code()); |
| 4677 | std::string response_data; |
| 4678 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4679 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4680 | |
| 4681 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4682 | // the next requests. |
| 4683 | trans.reset(); |
| 4684 | base::RunLoop().RunUntilIdle(); |
| 4685 | |
| 4686 | // Check the number of idle sockets in the pool, to make sure that used |
| 4687 | // sockets are indeed being returned to the socket pool. If each request |
| 4688 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4689 | // pass. |
| 4690 | EXPECT_EQ( |
| 4691 | test_case.expected_idle_socks_sockets, |
| 4692 | session |
| 4693 | ->GetSocketPoolForSOCKSProxy( |
| 4694 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4695 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4696 | ->IdleSocketCount()); |
| 4697 | EXPECT_EQ( |
| 4698 | test_case.expected_idle_http_sockets, |
| 4699 | session |
| 4700 | ->GetSocketPoolForHTTPProxy( |
| 4701 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4702 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4703 | ->IdleSocketCount()); |
| 4704 | } |
| 4705 | } |
| 4706 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4707 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4708 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4709 | HttpRequestInfo request1; |
| 4710 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4711 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4712 | |
| 4713 | HttpRequestInfo request2; |
| 4714 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4715 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4716 | |
| 4717 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4718 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4719 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4720 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4722 | |
| 4723 | // Since we have proxy, should try to establish tunnel. |
| 4724 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4725 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4726 | "Host: www.example.org:443\r\n" |
| 4727 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4728 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4729 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4730 | "Host: www.example.org\r\n" |
| 4731 | "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 /2 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 | }; |
| 4737 | |
| 4738 | // The proxy responds to the connect with a 407, using a persistent |
| 4739 | // connection. |
| 4740 | MockRead data_reads1[] = { |
| 4741 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4742 | |
| 4743 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4744 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4745 | MockRead(SYNCHRONOUS, "1"), |
| 4746 | |
| 4747 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4748 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4749 | MockRead(SYNCHRONOUS, "22"), |
| 4750 | }; |
| 4751 | |
| 4752 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4753 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4755 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4756 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4757 | |
| 4758 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4759 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4760 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4761 | |
| 4762 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4764 | |
| 4765 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4767 | |
| 4768 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4769 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4770 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4771 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4772 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4773 | |
| 4774 | LoadTimingInfo load_timing_info1; |
| 4775 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4776 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4777 | |
| 4778 | trans1.reset(); |
| 4779 | |
| 4780 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4781 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4782 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4783 | |
| 4784 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4786 | |
| 4787 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4788 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4789 | |
| 4790 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4791 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4792 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4793 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4794 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4795 | |
| 4796 | LoadTimingInfo load_timing_info2; |
| 4797 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4798 | TestLoadTimingReused(load_timing_info2); |
| 4799 | |
| 4800 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4801 | |
| 4802 | trans2.reset(); |
| 4803 | session->CloseAllConnections(); |
| 4804 | } |
| 4805 | |
| 4806 | // 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] | 4807 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4808 | HttpRequestInfo request1; |
| 4809 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4810 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4811 | |
| 4812 | HttpRequestInfo request2; |
| 4813 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4814 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4815 | |
| 4816 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4817 | session_deps_.proxy_service = |
| 4818 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4819 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4820 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4822 | |
| 4823 | // Since we have proxy, should try to establish tunnel. |
| 4824 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4825 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4826 | "Host: www.example.org:443\r\n" |
| 4827 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4828 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4829 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4830 | "Host: www.example.org\r\n" |
| 4831 | "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 /2 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 | }; |
| 4837 | |
| 4838 | // The proxy responds to the connect with a 407, using a persistent |
| 4839 | // connection. |
| 4840 | MockRead data_reads1[] = { |
| 4841 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4842 | |
| 4843 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4844 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4845 | MockRead(SYNCHRONOUS, "1"), |
| 4846 | |
| 4847 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4848 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4849 | MockRead(SYNCHRONOUS, "22"), |
| 4850 | }; |
| 4851 | |
| 4852 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4853 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4855 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4857 | |
| 4858 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4859 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4860 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4861 | |
| 4862 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4864 | |
| 4865 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4867 | |
| 4868 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4869 | ASSERT_TRUE(response1); |
| 4870 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4871 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4872 | |
| 4873 | LoadTimingInfo load_timing_info1; |
| 4874 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4875 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4876 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4877 | |
| 4878 | trans1.reset(); |
| 4879 | |
| 4880 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4881 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4882 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4883 | |
| 4884 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4886 | |
| 4887 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4888 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4889 | |
| 4890 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4891 | ASSERT_TRUE(response2); |
| 4892 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4893 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4894 | |
| 4895 | LoadTimingInfo load_timing_info2; |
| 4896 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4897 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4898 | |
| 4899 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4900 | |
| 4901 | trans2.reset(); |
| 4902 | session->CloseAllConnections(); |
| 4903 | } |
| 4904 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4905 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4906 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4907 | HttpRequestInfo request; |
| 4908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4909 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4910 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4911 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4912 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4913 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4914 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4916 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4917 | // Since we have proxy, should use full url |
| 4918 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4919 | MockWrite( |
| 4920 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4921 | "Host: www.example.org\r\n" |
| 4922 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4923 | }; |
| 4924 | |
| 4925 | MockRead data_reads1[] = { |
| 4926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4928 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4929 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4930 | }; |
| 4931 | |
| 4932 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4933 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4934 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4935 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4937 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4938 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4942 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4943 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4944 | |
| 4945 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4946 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4947 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4948 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4949 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4950 | TestLoadTimingNotReused(load_timing_info, |
| 4951 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4953 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4954 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4955 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4956 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4957 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4958 | EXPECT_EQ(200, response->headers->response_code()); |
| 4959 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4960 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4961 | |
| 4962 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4963 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4964 | } |
| 4965 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4966 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4967 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4968 | HttpRequestInfo request; |
| 4969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4970 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4971 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4972 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4973 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4974 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4975 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4977 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4978 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4979 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4980 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4981 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4982 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4983 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4984 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4985 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4986 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4987 | }; |
| 4988 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4989 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4990 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4991 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4992 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4993 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4994 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4997 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5001 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5003 | |
| 5004 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5006 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5007 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5008 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5009 | TestLoadTimingNotReused(load_timing_info, |
| 5010 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5012 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5013 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5014 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5015 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5016 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5017 | |
| 5018 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5019 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5020 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5021 | } |
| 5022 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5023 | // Verifies that a session which races and wins against the owning transaction |
| 5024 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5025 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5026 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5027 | HttpRequestInfo request; |
| 5028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5029 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5030 | |
| 5031 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5032 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5033 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5034 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5036 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5037 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5038 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5039 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5040 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5041 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5042 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5043 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5044 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5045 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5046 | }; |
| 5047 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5048 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5049 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5050 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5051 | |
| 5052 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5053 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5055 | |
| 5056 | TestCompletionCallback callback1; |
| 5057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5058 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5059 | |
| 5060 | // Stall the hostname resolution begun by the transaction. |
| 5061 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 5062 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5064 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5066 | |
| 5067 | // Race a session to the proxy, which completes first. |
| 5068 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 5069 | SpdySessionKey key( |
| 5070 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 5071 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5072 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5073 | |
| 5074 | // Unstall the resolution begun by the transaction. |
| 5075 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5076 | session_deps_.host_resolver->ResolveAllPending(); |
| 5077 | |
| 5078 | EXPECT_FALSE(callback1.have_result()); |
| 5079 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5082 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5083 | ASSERT_TRUE(response); |
| 5084 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5085 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5086 | |
| 5087 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5088 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5089 | EXPECT_EQ(kUploadData, response_data); |
| 5090 | } |
| 5091 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5092 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5093 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5094 | HttpRequestInfo request; |
| 5095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5096 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5097 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5098 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5099 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5100 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5101 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5103 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5104 | // The first request will be a bare GET, the second request will be a |
| 5105 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5106 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5107 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5108 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5109 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5110 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5111 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5112 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5113 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 5114 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 5115 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5116 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5117 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5118 | }; |
| 5119 | |
| 5120 | // The first response is a 407 proxy authentication challenge, and the second |
| 5121 | // response will be a 200 response since the second request includes a valid |
| 5122 | // Authorization header. |
| 5123 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5124 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5125 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5126 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 5127 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5128 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5129 | SpdySerializedFrame body_authentication( |
| 5130 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5131 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5132 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5133 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5134 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5135 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5136 | CreateMockRead(resp_data, 4), |
| 5137 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5138 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5139 | }; |
| 5140 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5141 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5142 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5144 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5145 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5146 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5149 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5153 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5155 | |
| 5156 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5157 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5159 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5160 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5161 | ASSERT_TRUE(response); |
| 5162 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5163 | EXPECT_EQ(407, response->headers->response_code()); |
| 5164 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5165 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5167 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5169 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5171 | |
| 5172 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5175 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5176 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5177 | ASSERT_TRUE(response_restart); |
| 5178 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5179 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5180 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5181 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5182 | } |
| 5183 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5184 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5185 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5186 | HttpRequestInfo request; |
| 5187 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5188 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5189 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5190 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5191 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5192 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5193 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5196 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5197 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5198 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5199 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5200 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5201 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5202 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5203 | const char get[] = |
| 5204 | "GET / HTTP/1.1\r\n" |
| 5205 | "Host: www.example.org\r\n" |
| 5206 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5207 | SpdySerializedFrame wrapped_get( |
| 5208 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5209 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5210 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5211 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5212 | SpdySerializedFrame wrapped_get_resp( |
| 5213 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 5214 | SpdySerializedFrame wrapped_body( |
| 5215 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 5216 | SpdySerializedFrame window_update( |
| 5217 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5218 | |
| 5219 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5220 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5221 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5222 | }; |
| 5223 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5224 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5226 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5227 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5228 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5229 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5230 | }; |
| 5231 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5232 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5233 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5234 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5235 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5236 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5237 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5239 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5242 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5244 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5246 | |
| 5247 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5248 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5249 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5250 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5251 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5252 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5254 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5255 | ASSERT_TRUE(response); |
| 5256 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5257 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5258 | |
| 5259 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5260 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5261 | EXPECT_EQ("1234567890", response_data); |
| 5262 | } |
| 5263 | |
| 5264 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5265 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5266 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5267 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5268 | HttpRequestInfo request; |
| 5269 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5270 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5271 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5272 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5273 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5274 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5275 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5279 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5280 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5281 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5282 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5283 | // fetch https://www.example.org/ via SPDY |
| 5284 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5285 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5286 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5287 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5288 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5289 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5290 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5291 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5292 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5293 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5294 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5295 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5296 | SpdySerializedFrame window_update_get_resp( |
| 5297 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5298 | SpdySerializedFrame window_update_body( |
| 5299 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5300 | |
| 5301 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5302 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5303 | CreateMockWrite(window_update_get_resp, 6), |
| 5304 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5305 | }; |
| 5306 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5307 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5308 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5309 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5310 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5311 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5312 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5313 | }; |
| 5314 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5315 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5316 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5317 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5318 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5319 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5320 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5322 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5323 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5326 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5328 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5330 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5331 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5332 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5333 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5334 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5335 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5337 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5338 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5339 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5340 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5341 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5342 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5343 | ASSERT_TRUE(response); |
| 5344 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5345 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5346 | |
| 5347 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5348 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5349 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5350 | } |
| 5351 | |
| 5352 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5353 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5354 | HttpRequestInfo request; |
| 5355 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5356 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5357 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5358 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5359 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5360 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5361 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5362 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5363 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5364 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5365 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5366 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5367 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5368 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5369 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5370 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5371 | |
| 5372 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5373 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5374 | }; |
| 5375 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5376 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5377 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5378 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5379 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5380 | }; |
| 5381 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5382 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5383 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5384 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5385 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5386 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5387 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5389 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5390 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5392 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5393 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5395 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5397 | |
| 5398 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5399 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5400 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5401 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5402 | } |
| 5403 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5404 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5405 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5406 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5407 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5408 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5409 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5410 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5411 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5412 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5413 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5414 | |
| 5415 | HttpRequestInfo request1; |
| 5416 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5417 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5418 | request1.load_flags = 0; |
| 5419 | |
| 5420 | HttpRequestInfo request2; |
| 5421 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5422 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5423 | request2.load_flags = 0; |
| 5424 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5425 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5426 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5427 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5428 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5429 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5430 | // Fetch https://www.example.org/ via HTTP. |
| 5431 | const char get1[] = |
| 5432 | "GET / HTTP/1.1\r\n" |
| 5433 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5434 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5435 | SpdySerializedFrame wrapped_get1( |
| 5436 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5437 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5438 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5439 | SpdySerializedFrame wrapped_get_resp1( |
| 5440 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5441 | SpdySerializedFrame wrapped_body1( |
| 5442 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5443 | SpdySerializedFrame window_update( |
| 5444 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5445 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5446 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5447 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5448 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5449 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5450 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5451 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5452 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5453 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5454 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5455 | // Fetch https://mail.example.org/ via HTTP. |
| 5456 | const char get2[] = |
| 5457 | "GET / HTTP/1.1\r\n" |
| 5458 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5459 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5460 | SpdySerializedFrame wrapped_get2( |
| 5461 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5462 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5463 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5464 | SpdySerializedFrame wrapped_get_resp2( |
| 5465 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5466 | SpdySerializedFrame wrapped_body2( |
| 5467 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5468 | |
| 5469 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5470 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5471 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5472 | }; |
| 5473 | |
| 5474 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5475 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5476 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5477 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5478 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5479 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5480 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5481 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5482 | }; |
| 5483 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5484 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5485 | arraysize(spdy_writes)); |
| 5486 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5487 | |
| 5488 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5489 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5491 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5493 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5494 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5495 | |
| 5496 | TestCompletionCallback callback; |
| 5497 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5499 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5500 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5501 | |
| 5502 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5503 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5504 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5506 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5507 | ASSERT_TRUE(response); |
| 5508 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5509 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5510 | |
| 5511 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5512 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5513 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5514 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5516 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5517 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5518 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5519 | |
| 5520 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5521 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5522 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5523 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5524 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5525 | |
| 5526 | // The requests should have different IDs, since they each are using their own |
| 5527 | // separate stream. |
| 5528 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5530 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5531 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5532 | } |
| 5533 | |
| 5534 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5535 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5536 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5537 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5538 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5539 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5540 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5541 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5542 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5543 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5544 | |
| 5545 | HttpRequestInfo request1; |
| 5546 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5547 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5548 | request1.load_flags = 0; |
| 5549 | |
| 5550 | HttpRequestInfo request2; |
| 5551 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5552 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5553 | request2.load_flags = 0; |
| 5554 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5555 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5556 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5557 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5558 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5559 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5560 | // Fetch https://www.example.org/ via HTTP. |
| 5561 | const char get1[] = |
| 5562 | "GET / HTTP/1.1\r\n" |
| 5563 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5564 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5565 | SpdySerializedFrame wrapped_get1( |
| 5566 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5567 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5568 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5569 | SpdySerializedFrame wrapped_get_resp1( |
| 5570 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5571 | SpdySerializedFrame wrapped_body1( |
| 5572 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5573 | SpdySerializedFrame window_update( |
| 5574 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5575 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5576 | // Fetch https://www.example.org/2 via HTTP. |
| 5577 | const char get2[] = |
| 5578 | "GET /2 HTTP/1.1\r\n" |
| 5579 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5580 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5581 | SpdySerializedFrame wrapped_get2( |
| 5582 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5583 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5584 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5585 | SpdySerializedFrame wrapped_get_resp2( |
| 5586 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5587 | SpdySerializedFrame wrapped_body2( |
| 5588 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5589 | |
| 5590 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5591 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5592 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5593 | }; |
| 5594 | |
| 5595 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5596 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5597 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5598 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5599 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5600 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5601 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5602 | }; |
| 5603 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5604 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5605 | arraysize(spdy_writes)); |
| 5606 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5607 | |
| 5608 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5609 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5611 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5613 | |
| 5614 | TestCompletionCallback callback; |
| 5615 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5616 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5617 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5618 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5620 | |
| 5621 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5622 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5623 | |
| 5624 | LoadTimingInfo load_timing_info; |
| 5625 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5626 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5627 | |
| 5628 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5629 | ASSERT_TRUE(response); |
| 5630 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5631 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5632 | |
| 5633 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5634 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5635 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5636 | trans.reset(); |
| 5637 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5638 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5639 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5640 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5642 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5643 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5645 | |
| 5646 | LoadTimingInfo load_timing_info2; |
| 5647 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5648 | TestLoadTimingReused(load_timing_info2); |
| 5649 | |
| 5650 | // The requests should have the same ID. |
| 5651 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5652 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5653 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5654 | } |
| 5655 | |
| 5656 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5657 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5658 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5659 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5660 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5661 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5662 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5663 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5664 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5665 | |
| 5666 | HttpRequestInfo request1; |
| 5667 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5668 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5669 | request1.load_flags = 0; |
| 5670 | |
| 5671 | HttpRequestInfo request2; |
| 5672 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5673 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5674 | request2.load_flags = 0; |
| 5675 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5676 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5677 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5678 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5679 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5680 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5681 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5682 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5683 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5684 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5685 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5686 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5687 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5688 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5689 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5690 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5691 | SpdySerializedFrame body2( |
| 5692 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5693 | |
| 5694 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5695 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5696 | }; |
| 5697 | |
| 5698 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5699 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5700 | CreateMockRead(body1, 2, ASYNC), |
| 5701 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5702 | CreateMockRead(body2, 5, ASYNC), |
| 5703 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5704 | }; |
| 5705 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5706 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5707 | arraysize(spdy_writes)); |
| 5708 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5709 | |
| 5710 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5711 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5713 | |
| 5714 | TestCompletionCallback callback; |
| 5715 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5716 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5717 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5718 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5719 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5720 | |
| 5721 | LoadTimingInfo load_timing_info; |
| 5722 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5723 | TestLoadTimingNotReused(load_timing_info, |
| 5724 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5725 | |
| 5726 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5727 | ASSERT_TRUE(response); |
| 5728 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5729 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5730 | |
| 5731 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5732 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5733 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5734 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5735 | // Delete the first request, so the second one can reuse the socket. |
| 5736 | trans.reset(); |
| 5737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5738 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5739 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5740 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5741 | |
| 5742 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5743 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5744 | TestLoadTimingReused(load_timing_info2); |
| 5745 | |
| 5746 | // The requests should have the same ID. |
| 5747 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5749 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5750 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5751 | } |
| 5752 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5753 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5754 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5755 | HttpRequestInfo request; |
| 5756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5757 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5758 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5759 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5760 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5761 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5762 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5763 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5764 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5766 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5767 | // Since we have proxy, should use full url |
| 5768 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5769 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5770 | "Host: www.example.org\r\n" |
| 5771 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5773 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5774 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5775 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5776 | "Host: www.example.org\r\n" |
| 5777 | "Proxy-Connection: keep-alive\r\n" |
| 5778 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5779 | }; |
| 5780 | |
| 5781 | // The proxy responds to the GET with a 407, using a persistent |
| 5782 | // connection. |
| 5783 | MockRead data_reads1[] = { |
| 5784 | // No credentials. |
| 5785 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5786 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5787 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5788 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5789 | |
| 5790 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5791 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5792 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5793 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5794 | }; |
| 5795 | |
| 5796 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5797 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5798 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5799 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5800 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5802 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5806 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5808 | |
| 5809 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5810 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5811 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5812 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5813 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5814 | TestLoadTimingNotReused(load_timing_info, |
| 5815 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5818 | ASSERT_TRUE(response); |
| 5819 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5820 | EXPECT_EQ(407, response->headers->response_code()); |
| 5821 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5822 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5824 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5826 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5828 | |
| 5829 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5831 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5832 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5834 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5835 | TestLoadTimingReused(load_timing_info); |
| 5836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5838 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5839 | |
| 5840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5841 | EXPECT_EQ(200, response->headers->response_code()); |
| 5842 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5843 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5844 | |
| 5845 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5846 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5847 | } |
| 5848 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5849 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5850 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5851 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5852 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5853 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5854 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5855 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5856 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5858 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5859 | // Since we have proxy, should try to establish tunnel. |
| 5860 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5861 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5862 | "Host: www.example.org:443\r\n" |
| 5863 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5864 | }; |
| 5865 | |
| 5866 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5867 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5868 | // No response body because the test stops reading here. |
| 5869 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5870 | }; |
| 5871 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5872 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5873 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5874 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5876 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5877 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5879 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5880 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5882 | |
| 5883 | rv = callback.WaitForResult(); |
| 5884 | EXPECT_EQ(expected_status, rv); |
| 5885 | } |
| 5886 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5887 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5888 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5889 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5890 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5891 | } |
| 5892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5893 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5894 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5895 | } |
| 5896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5897 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5898 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5899 | } |
| 5900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5901 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5902 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5903 | } |
| 5904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5905 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5906 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5907 | } |
| 5908 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5909 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5910 | ConnectStatusHelper( |
| 5911 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5912 | } |
| 5913 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5914 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5915 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5916 | } |
| 5917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5919 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5920 | } |
| 5921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5923 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5924 | } |
| 5925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5927 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5928 | } |
| 5929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5931 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5932 | } |
| 5933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5935 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5936 | } |
| 5937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5939 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5940 | } |
| 5941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5943 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5944 | } |
| 5945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5947 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5948 | } |
| 5949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5951 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5952 | } |
| 5953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5955 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5956 | } |
| 5957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5959 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5960 | } |
| 5961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5963 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5964 | } |
| 5965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5966 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5967 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5968 | } |
| 5969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5970 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5971 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5972 | } |
| 5973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5974 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5975 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5976 | } |
| 5977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5978 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5979 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5980 | } |
| 5981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5982 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5983 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5984 | } |
| 5985 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5986 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5987 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5988 | } |
| 5989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5990 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5991 | ConnectStatusHelperWithExpectedStatus( |
| 5992 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5993 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5994 | } |
| 5995 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5996 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5997 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5998 | } |
| 5999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6000 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6001 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6002 | } |
| 6003 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6004 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6005 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6006 | } |
| 6007 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6008 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6009 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6010 | } |
| 6011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6012 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6013 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6014 | } |
| 6015 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6016 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6017 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6018 | } |
| 6019 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6020 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6021 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6022 | } |
| 6023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6024 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6025 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6026 | } |
| 6027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6028 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6029 | ConnectStatusHelper( |
| 6030 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6031 | } |
| 6032 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6033 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6034 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6035 | } |
| 6036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6037 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6038 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6039 | } |
| 6040 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6041 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6042 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6043 | } |
| 6044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6045 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6046 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6047 | } |
| 6048 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6049 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6050 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6051 | } |
| 6052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6053 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6054 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6055 | } |
| 6056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6057 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6058 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6059 | } |
| 6060 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6061 | // Test the flow when both the proxy server AND origin server require |
| 6062 | // authentication. Again, this uses basic auth for both since that is |
| 6063 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6064 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6065 | HttpRequestInfo request; |
| 6066 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6067 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6068 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6069 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6070 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6074 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6075 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6076 | MockWrite( |
| 6077 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6078 | "Host: www.example.org\r\n" |
| 6079 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6080 | }; |
| 6081 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6082 | MockRead data_reads1[] = { |
| 6083 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6084 | // Give a couple authenticate options (only the middle one is actually |
| 6085 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6086 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6087 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6088 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6089 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6090 | // Large content-length -- won't matter, as connection will be reset. |
| 6091 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6092 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6093 | }; |
| 6094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6095 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6096 | // request we should be issuing -- the final header line contains the |
| 6097 | // proxy's credentials. |
| 6098 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6099 | MockWrite( |
| 6100 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6101 | "Host: www.example.org\r\n" |
| 6102 | "Proxy-Connection: keep-alive\r\n" |
| 6103 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6104 | }; |
| 6105 | |
| 6106 | // Now the proxy server lets the request pass through to origin server. |
| 6107 | // The origin server responds with a 401. |
| 6108 | MockRead data_reads2[] = { |
| 6109 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6110 | // Note: We are using the same realm-name as the proxy server. This is |
| 6111 | // completely valid, as realms are unique across hosts. |
| 6112 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6113 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6114 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6115 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6116 | }; |
| 6117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6118 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6119 | // the credentials for both the proxy and origin server. |
| 6120 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6121 | MockWrite( |
| 6122 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6123 | "Host: www.example.org\r\n" |
| 6124 | "Proxy-Connection: keep-alive\r\n" |
| 6125 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6126 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6127 | }; |
| 6128 | |
| 6129 | // Lastly we get the desired content. |
| 6130 | MockRead data_reads3[] = { |
| 6131 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6132 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6133 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6134 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6135 | }; |
| 6136 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6137 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6138 | data_writes1, arraysize(data_writes1)); |
| 6139 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6140 | data_writes2, arraysize(data_writes2)); |
| 6141 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6142 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6143 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6144 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6145 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6146 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6147 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6148 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6149 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6150 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6151 | |
| 6152 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6153 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6155 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6156 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6157 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6159 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6163 | |
| 6164 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6165 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6167 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6168 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6169 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6171 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6172 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6173 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6174 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6176 | |
| 6177 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6180 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6181 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6182 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6183 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6184 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6185 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6186 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6187 | // authorization headers. |
| 6188 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6189 | // The NTLM authentication unit tests are based on known test data from the |
| 6190 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6191 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6192 | // for the implementation and testing of the protocol. |
| 6193 | // |
| 6194 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6195 | |
| 6196 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6197 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6198 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6199 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6200 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6201 | |
| 6202 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6203 | // to other auth schemes. |
| 6204 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6205 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6206 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6207 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6208 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6209 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6210 | // Generate the NTLM messages based on known test data. |
| 6211 | std::string negotiate_msg; |
| 6212 | std::string challenge_msg; |
| 6213 | std::string authenticate_msg; |
| 6214 | base::Base64Encode( |
| 6215 | base::StringPiece( |
| 6216 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6217 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6218 | &negotiate_msg); |
| 6219 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6220 | ntlm::test::kChallengeMsgV1), |
| 6221 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6222 | &challenge_msg); |
| 6223 | base::Base64Encode( |
| 6224 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6225 | reinterpret_cast<const char*>( |
| 6226 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6227 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6228 | &authenticate_msg); |
| 6229 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6230 | MockWrite data_writes1[] = { |
| 6231 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6232 | "Host: 172.22.68.17\r\n" |
| 6233 | "Connection: keep-alive\r\n\r\n"), |
| 6234 | }; |
| 6235 | |
| 6236 | MockRead data_reads1[] = { |
| 6237 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6238 | // Negotiate and NTLM are often requested together. However, we only want |
| 6239 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6240 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6241 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6242 | MockRead("Connection: close\r\n"), |
| 6243 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6244 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6245 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6246 | }; |
| 6247 | |
| 6248 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6249 | // After restarting with a null identity, this is the |
| 6250 | // request we should be issuing -- the final header line contains a Type |
| 6251 | // 1 message. |
| 6252 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6253 | "Host: 172.22.68.17\r\n" |
| 6254 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6255 | "Authorization: NTLM "), |
| 6256 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6258 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6259 | // (using correct credentials). The second request continues on the |
| 6260 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6261 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6262 | "Host: 172.22.68.17\r\n" |
| 6263 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6264 | "Authorization: NTLM "), |
| 6265 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6266 | }; |
| 6267 | |
| 6268 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6269 | // The origin server responds with a Type 2 message. |
| 6270 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6271 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6272 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6273 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6274 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6275 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6276 | // Lastly we get the desired content. |
| 6277 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6278 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6279 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6280 | }; |
| 6281 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6282 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6283 | data_writes1, arraysize(data_writes1)); |
| 6284 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6285 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6286 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6287 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6288 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6289 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6290 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6291 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6294 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6298 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6300 | |
| 6301 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6304 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6305 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6306 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6307 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6308 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6309 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6310 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6311 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6312 | rv = trans.RestartWithAuth( |
| 6313 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6314 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6316 | |
| 6317 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6320 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6322 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6323 | ASSERT_TRUE(response); |
| 6324 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6326 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6327 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6328 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6330 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6331 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6334 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6335 | ASSERT_TRUE(response); |
| 6336 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6337 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6338 | |
| 6339 | std::string response_data; |
| 6340 | rv = ReadTransaction(&trans, &response_data); |
| 6341 | EXPECT_THAT(rv, IsOk()); |
| 6342 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6343 | |
| 6344 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6345 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6346 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6347 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6348 | } |
| 6349 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6350 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6351 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6352 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6353 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6354 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6355 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6356 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6357 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6358 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6359 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6360 | // Generate the NTLM messages based on known test data. |
| 6361 | std::string negotiate_msg; |
| 6362 | std::string challenge_msg; |
| 6363 | std::string authenticate_msg; |
| 6364 | base::Base64Encode( |
| 6365 | base::StringPiece( |
| 6366 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6367 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6368 | &negotiate_msg); |
| 6369 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6370 | ntlm::test::kChallengeMsgV1), |
| 6371 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6372 | &challenge_msg); |
| 6373 | base::Base64Encode( |
| 6374 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6375 | reinterpret_cast<const char*>( |
| 6376 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6377 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6378 | &authenticate_msg); |
| 6379 | |
| 6380 | // The authenticate message when |kWrongPassword| is sent. |
| 6381 | std::string wrong_password_authenticate_msg( |
| 6382 | "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAwADABwAAAACAAIAHwAAAAQABAAhAAAAAAA" |
| 6383 | "AABAAAAAA4IIAKqqqqqqqqqqAAAAAAAAAAAAAAAAAAAAAF2npafgDxlql9qxEIhLlsuuJIEd" |
| 6384 | "NQHk7kQAbwBtAGEAaQBuAFUAcwBlAHIAQwBPAE0AUABVAFQARQBSAA=="); |
| 6385 | |
| 6386 | // Sanity check that this is the same as |authenticate_msg| except for the |
| 6387 | // 24 bytes (32 encoded chars) of the NTLM Response. |
| 6388 | ASSERT_EQ(authenticate_msg.length(), |
| 6389 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6390 | ASSERT_EQ(authenticate_msg.length(), 200u); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6391 | ASSERT_EQ(base::StringPiece(authenticate_msg.data(), 117), |
| 6392 | base::StringPiece(wrong_password_authenticate_msg.data(), 117)); |
| 6393 | ASSERT_EQ( |
| 6394 | base::StringPiece(authenticate_msg.data() + 149, 51), |
| 6395 | base::StringPiece(wrong_password_authenticate_msg.data() + 149, 51)); |
| 6396 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6397 | MockWrite data_writes1[] = { |
| 6398 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6399 | "Host: 172.22.68.17\r\n" |
| 6400 | "Connection: keep-alive\r\n\r\n"), |
| 6401 | }; |
| 6402 | |
| 6403 | MockRead data_reads1[] = { |
| 6404 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6405 | // Negotiate and NTLM are often requested together. However, we only want |
| 6406 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6407 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6408 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6409 | MockRead("Connection: close\r\n"), |
| 6410 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6411 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6412 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6413 | }; |
| 6414 | |
| 6415 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6416 | // After restarting with a null identity, this is the |
| 6417 | // request we should be issuing -- the final header line contains a Type |
| 6418 | // 1 message. |
| 6419 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6420 | "Host: 172.22.68.17\r\n" |
| 6421 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6422 | "Authorization: NTLM "), |
| 6423 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6424 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6425 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6426 | // (using incorrect credentials). The second request continues on the |
| 6427 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6428 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6429 | "Host: 172.22.68.17\r\n" |
| 6430 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6431 | "Authorization: NTLM "), |
| 6432 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6433 | }; |
| 6434 | |
| 6435 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6436 | // The origin server responds with a Type 2 message. |
| 6437 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6438 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6439 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6440 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6441 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6442 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6443 | // Wrong password. |
| 6444 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6445 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6446 | MockRead("Content-Length: 42\r\n"), |
| 6447 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6448 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6449 | }; |
| 6450 | |
| 6451 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6452 | // After restarting with a null identity, this is the |
| 6453 | // request we should be issuing -- the final header line contains a Type |
| 6454 | // 1 message. |
| 6455 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6456 | "Host: 172.22.68.17\r\n" |
| 6457 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6458 | "Authorization: NTLM "), |
| 6459 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6460 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6461 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6462 | // (the credentials for the origin server). The second request continues |
| 6463 | // on the same connection. |
| 6464 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6465 | "Host: 172.22.68.17\r\n" |
| 6466 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6467 | "Authorization: NTLM "), |
| 6468 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6469 | }; |
| 6470 | |
| 6471 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6472 | // The origin server responds with a Type 2 message. |
| 6473 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6474 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6475 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6476 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6477 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6478 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6479 | // Lastly we get the desired content. |
| 6480 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6481 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6482 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6483 | }; |
| 6484 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6485 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6486 | data_writes1, arraysize(data_writes1)); |
| 6487 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6488 | data_writes2, arraysize(data_writes2)); |
| 6489 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6490 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6491 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6492 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6493 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6494 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6495 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6497 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6498 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6499 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6500 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6501 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6502 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6505 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6506 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6508 | |
| 6509 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6511 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6512 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6514 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6515 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6516 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6517 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6518 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6519 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6520 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6521 | rv = trans.RestartWithAuth( |
| 6522 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6523 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6524 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6525 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6526 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6527 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6529 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6530 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6531 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6533 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6534 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6535 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6537 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6538 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6539 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6541 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6542 | |
| 6543 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6544 | rv = trans.RestartWithAuth( |
| 6545 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6546 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6548 | |
| 6549 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6552 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6553 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6554 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6555 | |
| 6556 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6557 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6559 | |
| 6560 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6561 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6563 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6564 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6565 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6566 | |
| 6567 | std::string response_data; |
| 6568 | rv = ReadTransaction(&trans, &response_data); |
| 6569 | EXPECT_THAT(rv, IsOk()); |
| 6570 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6571 | |
| 6572 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6573 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6574 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6575 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6576 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6577 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6578 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6579 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6580 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6581 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6582 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6583 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6584 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6585 | |
| 6586 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6587 | |
| 6588 | HttpRequestInfo request; |
| 6589 | request.method = "GET"; |
| 6590 | request.url = GURL(kUrl); |
| 6591 | |
| 6592 | // First request without credentials. |
| 6593 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6594 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6595 | 1, std::move(request_headers0), LOWEST, true)); |
| 6596 | |
| 6597 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6598 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6599 | response_headers0["www-authenticate"] = "NTLM"; |
| 6600 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6601 | 1, std::move(response_headers0), true)); |
| 6602 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6603 | // Stream 1 is closed. |
| 6604 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6605 | |
| 6606 | // Generate the NTLM messages based on known test data. |
| 6607 | std::string negotiate_msg; |
| 6608 | std::string challenge_msg; |
| 6609 | std::string authenticate_msg; |
| 6610 | base::Base64Encode( |
| 6611 | base::StringPiece( |
| 6612 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6613 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6614 | &negotiate_msg); |
| 6615 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6616 | ntlm::test::kChallengeMsgV1), |
| 6617 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6618 | &challenge_msg); |
| 6619 | base::Base64Encode( |
| 6620 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6621 | reinterpret_cast<const char*>( |
| 6622 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6623 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6624 | &authenticate_msg); |
| 6625 | |
| 6626 | // Retry with authorization header. |
| 6627 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6628 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6629 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6630 | 3, std::move(request_headers1), LOWEST, true)); |
| 6631 | |
| 6632 | SpdySerializedFrame rst( |
| 6633 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6634 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6635 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6636 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6637 | |
| 6638 | // Retry yet again using HTTP/1.1. |
| 6639 | MockWrite writes1[] = { |
| 6640 | // After restarting with a null identity, this is the |
| 6641 | // request we should be issuing -- the final header line contains a Type |
| 6642 | // 1 message. |
| 6643 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6644 | "Host: 172.22.68.17\r\n" |
| 6645 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6646 | "Authorization: NTLM "), |
| 6647 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6648 | |
| 6649 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6650 | // (the credentials for the origin server). The second request continues |
| 6651 | // on the same connection. |
| 6652 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6653 | "Host: 172.22.68.17\r\n" |
| 6654 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6655 | "Authorization: NTLM "), |
| 6656 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6657 | }; |
| 6658 | |
| 6659 | MockRead reads1[] = { |
| 6660 | // The origin server responds with a Type 2 message. |
| 6661 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6662 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6663 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6664 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6665 | MockRead("You are not authorized to view this page\r\n"), |
| 6666 | |
| 6667 | // Lastly we get the desired content. |
| 6668 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6669 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6670 | 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] | 6671 | }; |
| 6672 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6673 | arraysize(writes0)); |
| 6674 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6675 | arraysize(writes1)); |
| 6676 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6677 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6678 | |
| 6679 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6680 | ssl0.next_proto = kProtoHTTP2; |
| 6681 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6682 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6684 | |
| 6685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6687 | |
| 6688 | TestCompletionCallback callback1; |
| 6689 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6691 | |
| 6692 | rv = callback1.WaitForResult(); |
| 6693 | EXPECT_THAT(rv, IsOk()); |
| 6694 | |
| 6695 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6696 | |
| 6697 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6698 | ASSERT_TRUE(response); |
| 6699 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6700 | |
| 6701 | TestCompletionCallback callback2; |
| 6702 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6703 | rv = trans.RestartWithAuth( |
| 6704 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6705 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6707 | |
| 6708 | rv = callback2.WaitForResult(); |
| 6709 | EXPECT_THAT(rv, IsOk()); |
| 6710 | |
| 6711 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6712 | |
| 6713 | response = trans.GetResponseInfo(); |
| 6714 | ASSERT_TRUE(response); |
| 6715 | EXPECT_FALSE(response->auth_challenge); |
| 6716 | |
| 6717 | TestCompletionCallback callback3; |
| 6718 | |
| 6719 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6721 | |
| 6722 | rv = callback3.WaitForResult(); |
| 6723 | EXPECT_THAT(rv, IsOk()); |
| 6724 | |
| 6725 | response = trans.GetResponseInfo(); |
| 6726 | ASSERT_TRUE(response); |
| 6727 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6728 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6729 | |
| 6730 | std::string response_data; |
| 6731 | rv = ReadTransaction(&trans, &response_data); |
| 6732 | EXPECT_THAT(rv, IsOk()); |
| 6733 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6734 | |
| 6735 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6736 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6737 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6738 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6739 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6740 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6741 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6742 | // Test reading a server response which has only headers, and no body. |
| 6743 | // After some maximum number of bytes is consumed, the transaction should |
| 6744 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6745 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6746 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6747 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6748 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6749 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6750 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6751 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6752 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6753 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6754 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6755 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6756 | |
| 6757 | MockRead data_reads[] = { |
| 6758 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6759 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6760 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6761 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6762 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6763 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6764 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6766 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6767 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6768 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6770 | |
| 6771 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6772 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6773 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6774 | |
| 6775 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6776 | // establish tunnel. |
| 6777 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6778 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6779 | HttpRequestInfo request; |
| 6780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6781 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6782 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6783 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6784 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6787 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6788 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6789 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6790 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6791 | // Since we have proxy, should try to establish tunnel. |
| 6792 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6793 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6794 | "Host: www.example.org:443\r\n" |
| 6795 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6796 | }; |
| 6797 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6798 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6799 | // connection. Usually a proxy would return 501 (not implemented), |
| 6800 | // or 200 (tunnel established). |
| 6801 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6802 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6803 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6804 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6805 | }; |
| 6806 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6807 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6808 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6809 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6811 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6813 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6815 | |
| 6816 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6817 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6818 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6819 | // Empty the current queue. This is necessary because idle sockets are |
| 6820 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6821 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6822 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6823 | // We now check to make sure the TCPClientSocket was not added back to |
| 6824 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6825 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6826 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6827 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6828 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6829 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6830 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6831 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6832 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6833 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6834 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6836 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6837 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6840 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6841 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6842 | MockRead data_reads[] = { |
| 6843 | // A part of the response body is received with the response headers. |
| 6844 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6845 | // The rest of the response body is received in two parts. |
| 6846 | MockRead("lo"), |
| 6847 | MockRead(" world"), |
| 6848 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6849 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6850 | }; |
| 6851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6852 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6853 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6855 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6856 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6857 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6859 | |
| 6860 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6861 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6862 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6863 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6864 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6865 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6866 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6867 | std::string status_line = response->headers->GetStatusLine(); |
| 6868 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6869 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6870 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6871 | |
| 6872 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6873 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6874 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6875 | EXPECT_EQ("hello world", response_data); |
| 6876 | |
| 6877 | // Empty the current queue. This is necessary because idle sockets are |
| 6878 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6879 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6880 | |
| 6881 | // 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] | 6882 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6883 | } |
| 6884 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6885 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6886 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6887 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6888 | HttpRequestInfo request; |
| 6889 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6890 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6891 | |
| 6892 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6893 | MockWrite( |
| 6894 | "GET / HTTP/1.1\r\n" |
| 6895 | "Host: www.example.org\r\n" |
| 6896 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6897 | }; |
| 6898 | |
| 6899 | MockRead data_reads[] = { |
| 6900 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6901 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6902 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6903 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6904 | }; |
| 6905 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6906 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6907 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6908 | |
| 6909 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6910 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6911 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6913 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6914 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6917 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6918 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6919 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6921 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6924 | ASSERT_TRUE(response); |
| 6925 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6926 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6927 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6928 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6929 | |
| 6930 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6931 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6932 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6933 | EXPECT_EQ("hello world", response_data); |
| 6934 | |
| 6935 | // Empty the current queue. This is necessary because idle sockets are |
| 6936 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6937 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6938 | |
| 6939 | // 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] | 6940 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6941 | } |
| 6942 | |
| 6943 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6944 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6945 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6946 | HttpRequestInfo request; |
| 6947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6948 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6949 | |
| 6950 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6951 | MockWrite( |
| 6952 | "GET / HTTP/1.1\r\n" |
| 6953 | "Host: www.example.org\r\n" |
| 6954 | "Connection: keep-alive\r\n\r\n"), |
| 6955 | MockWrite( |
| 6956 | "GET / HTTP/1.1\r\n" |
| 6957 | "Host: www.example.org\r\n" |
| 6958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6959 | }; |
| 6960 | |
| 6961 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6962 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6963 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6964 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6965 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6966 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6969 | |
| 6970 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6971 | data_writes, arraysize(data_writes)); |
| 6972 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6973 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6974 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6975 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6977 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6980 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6981 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6982 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6983 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6984 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6986 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6987 | |
| 6988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6989 | ASSERT_TRUE(response); |
| 6990 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6991 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6992 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6993 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6994 | |
| 6995 | std::string response_data; |
| 6996 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6998 | EXPECT_EQ("hello world", response_data); |
| 6999 | |
| 7000 | // Empty the current queue. This is necessary because idle sockets are |
| 7001 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7002 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7003 | |
| 7004 | // 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] | 7005 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7006 | |
| 7007 | // Now start the second transaction, which should reuse the previous socket. |
| 7008 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7009 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7010 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7012 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7013 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7015 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7016 | |
| 7017 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7018 | ASSERT_TRUE(response); |
| 7019 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7020 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7021 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7022 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7023 | |
| 7024 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7026 | EXPECT_EQ("hello world", response_data); |
| 7027 | |
| 7028 | // Empty the current queue. This is necessary because idle sockets are |
| 7029 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7030 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7031 | |
| 7032 | // 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] | 7033 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7034 | } |
| 7035 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7036 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7037 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7038 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7039 | HttpRequestInfo request; |
| 7040 | request.method = "GET"; |
| 7041 | request.url = GURL("http://www.example.org/"); |
| 7042 | request.load_flags = 0; |
| 7043 | |
| 7044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7047 | |
| 7048 | MockRead data_reads[] = { |
| 7049 | // A part of the response body is received with the response headers. |
| 7050 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7051 | // The rest of the response body is received in two parts. |
| 7052 | MockRead("lo"), MockRead(" world"), |
| 7053 | MockRead("junk"), // Should not be read!! |
| 7054 | MockRead(SYNCHRONOUS, OK), |
| 7055 | }; |
| 7056 | |
| 7057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7058 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7059 | |
| 7060 | TestCompletionCallback callback; |
| 7061 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7062 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7064 | |
| 7065 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7068 | ASSERT_TRUE(response); |
| 7069 | EXPECT_TRUE(response->headers); |
| 7070 | std::string status_line = response->headers->GetStatusLine(); |
| 7071 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7072 | |
| 7073 | // Make memory critical notification and ensure the transaction still has been |
| 7074 | // operating right. |
| 7075 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7076 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7077 | base::RunLoop().RunUntilIdle(); |
| 7078 | |
| 7079 | // Socket should not be flushed as long as it is not idle. |
| 7080 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7081 | |
| 7082 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7083 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7084 | EXPECT_THAT(rv, IsOk()); |
| 7085 | EXPECT_EQ("hello world", response_data); |
| 7086 | |
| 7087 | // Empty the current queue. This is necessary because idle sockets are |
| 7088 | // added to the connection pool asynchronously with a PostTask. |
| 7089 | base::RunLoop().RunUntilIdle(); |
| 7090 | |
| 7091 | // We now check to make sure the socket was added back to the pool. |
| 7092 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7093 | |
| 7094 | // Idle sockets should be flushed now. |
| 7095 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7096 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7097 | base::RunLoop().RunUntilIdle(); |
| 7098 | |
| 7099 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7100 | } |
| 7101 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7102 | // Disable idle socket closing on memory pressure. |
| 7103 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7104 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7105 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7106 | HttpRequestInfo request; |
| 7107 | request.method = "GET"; |
| 7108 | request.url = GURL("http://www.example.org/"); |
| 7109 | request.load_flags = 0; |
| 7110 | |
| 7111 | // Disable idle socket closing on memory pressure. |
| 7112 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7114 | |
| 7115 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7116 | |
| 7117 | MockRead data_reads[] = { |
| 7118 | // A part of the response body is received with the response headers. |
| 7119 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7120 | // The rest of the response body is received in two parts. |
| 7121 | MockRead("lo"), MockRead(" world"), |
| 7122 | MockRead("junk"), // Should not be read!! |
| 7123 | MockRead(SYNCHRONOUS, OK), |
| 7124 | }; |
| 7125 | |
| 7126 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 7127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7128 | |
| 7129 | TestCompletionCallback callback; |
| 7130 | |
| 7131 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7133 | |
| 7134 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7135 | |
| 7136 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7137 | ASSERT_TRUE(response); |
| 7138 | EXPECT_TRUE(response->headers); |
| 7139 | std::string status_line = response->headers->GetStatusLine(); |
| 7140 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7141 | |
| 7142 | // Make memory critical notification and ensure the transaction still has been |
| 7143 | // operating right. |
| 7144 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7145 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7146 | base::RunLoop().RunUntilIdle(); |
| 7147 | |
| 7148 | // Socket should not be flushed as long as it is not idle. |
| 7149 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7150 | |
| 7151 | std::string response_data; |
| 7152 | rv = ReadTransaction(&trans, &response_data); |
| 7153 | EXPECT_THAT(rv, IsOk()); |
| 7154 | EXPECT_EQ("hello world", response_data); |
| 7155 | |
| 7156 | // Empty the current queue. This is necessary because idle sockets are |
| 7157 | // added to the connection pool asynchronously with a PostTask. |
| 7158 | base::RunLoop().RunUntilIdle(); |
| 7159 | |
| 7160 | // We now check to make sure the socket was added back to the pool. |
| 7161 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7162 | |
| 7163 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7164 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7165 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7166 | base::RunLoop().RunUntilIdle(); |
| 7167 | |
| 7168 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7169 | |
| 7170 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7171 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7172 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7173 | base::RunLoop().RunUntilIdle(); |
| 7174 | |
| 7175 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7176 | } |
| 7177 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7178 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7179 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7180 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7181 | HttpRequestInfo request; |
| 7182 | request.method = "GET"; |
| 7183 | request.url = GURL("https://www.example.org/"); |
| 7184 | request.load_flags = 0; |
| 7185 | |
| 7186 | MockWrite data_writes[] = { |
| 7187 | MockWrite("GET / HTTP/1.1\r\n" |
| 7188 | "Host: www.example.org\r\n" |
| 7189 | "Connection: keep-alive\r\n\r\n"), |
| 7190 | }; |
| 7191 | |
| 7192 | MockRead data_reads[] = { |
| 7193 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7194 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7195 | |
| 7196 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7197 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7198 | |
| 7199 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 7200 | arraysize(data_writes)); |
| 7201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7202 | |
| 7203 | TestCompletionCallback callback; |
| 7204 | |
| 7205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7206 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7207 | |
| 7208 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7209 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7210 | |
| 7211 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7213 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7214 | ASSERT_TRUE(response); |
| 7215 | ASSERT_TRUE(response->headers); |
| 7216 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7217 | |
| 7218 | // Make memory critical notification and ensure the transaction still has been |
| 7219 | // operating right. |
| 7220 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7221 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7222 | base::RunLoop().RunUntilIdle(); |
| 7223 | |
| 7224 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7225 | |
| 7226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7228 | EXPECT_THAT(rv, IsOk()); |
| 7229 | EXPECT_EQ("hello world", response_data); |
| 7230 | |
| 7231 | // Empty the current queue. This is necessary because idle sockets are |
| 7232 | // added to the connection pool asynchronously with a PostTask. |
| 7233 | base::RunLoop().RunUntilIdle(); |
| 7234 | |
| 7235 | // We now check to make sure the socket was added back to the pool. |
| 7236 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7237 | |
| 7238 | // Make memory notification once again and ensure idle socket is closed. |
| 7239 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7240 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7241 | base::RunLoop().RunUntilIdle(); |
| 7242 | |
| 7243 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7244 | } |
| 7245 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7246 | // Make sure that we recycle a socket after a zero-length response. |
| 7247 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7248 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7249 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7250 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7251 | request.url = GURL( |
| 7252 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7253 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7254 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7255 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7256 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7257 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7258 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7259 | MockRead data_reads[] = { |
| 7260 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7261 | "Content-Length: 0\r\n" |
| 7262 | "Content-Type: text/html\r\n\r\n"), |
| 7263 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7265 | }; |
| 7266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7268 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7269 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7270 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7271 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7274 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7275 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7276 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7278 | |
| 7279 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7282 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7283 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7284 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7285 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7286 | std::string status_line = response->headers->GetStatusLine(); |
| 7287 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7288 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7289 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7290 | |
| 7291 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7293 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7294 | EXPECT_EQ("", response_data); |
| 7295 | |
| 7296 | // Empty the current queue. This is necessary because idle sockets are |
| 7297 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7298 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7299 | |
| 7300 | // 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] | 7301 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7302 | } |
| 7303 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7304 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7305 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7306 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7307 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7308 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7309 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7310 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7311 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7312 | // after use. |
| 7313 | request[0].method = "GET"; |
| 7314 | request[0].url = GURL("http://www.google.com/"); |
| 7315 | request[0].load_flags = 0; |
| 7316 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7317 | // transaction 1. The first attempts fails when writing the POST data. |
| 7318 | // This causes the transaction to retry with a new socket. The second |
| 7319 | // attempt succeeds. |
| 7320 | request[1].method = "POST"; |
| 7321 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7322 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7323 | request[1].load_flags = 0; |
| 7324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7326 | |
| 7327 | // The first socket is used for transaction 1 and the first attempt of |
| 7328 | // transaction 2. |
| 7329 | |
| 7330 | // The response of transaction 1. |
| 7331 | MockRead data_reads1[] = { |
| 7332 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7333 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7334 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7335 | }; |
| 7336 | // The mock write results of transaction 1 and the first attempt of |
| 7337 | // transaction 2. |
| 7338 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7339 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7340 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7341 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7342 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7343 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7344 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7345 | |
| 7346 | // The second socket is used for the second attempt of transaction 2. |
| 7347 | |
| 7348 | // The response of transaction 2. |
| 7349 | MockRead data_reads2[] = { |
| 7350 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7351 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7352 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7353 | }; |
| 7354 | // The mock write results of the second attempt of transaction 2. |
| 7355 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7356 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7357 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7358 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7359 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7360 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7361 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7362 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7363 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7364 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7365 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7366 | "hello world", "welcome" |
| 7367 | }; |
| 7368 | |
| 7369 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7370 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7372 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7373 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7374 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7376 | |
| 7377 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7378 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7379 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7380 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7381 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7382 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7383 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7384 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7385 | |
| 7386 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7388 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7389 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7390 | } |
| 7391 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7392 | |
| 7393 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7394 | // 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] | 7395 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7396 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7397 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7399 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7400 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7401 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7404 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7405 | // The password contains an escaped character -- for this test to pass it |
| 7406 | // will need to be unescaped by HttpNetworkTransaction. |
| 7407 | EXPECT_EQ("b%40r", request.url.password()); |
| 7408 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7409 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7410 | MockWrite( |
| 7411 | "GET / HTTP/1.1\r\n" |
| 7412 | "Host: www.example.org\r\n" |
| 7413 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7414 | }; |
| 7415 | |
| 7416 | MockRead data_reads1[] = { |
| 7417 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7418 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7419 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7420 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7421 | }; |
| 7422 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7423 | // After the challenge above, the transaction will be restarted using the |
| 7424 | // identity from the url (foo, b@r) to answer the challenge. |
| 7425 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | MockWrite( |
| 7427 | "GET / HTTP/1.1\r\n" |
| 7428 | "Host: www.example.org\r\n" |
| 7429 | "Connection: keep-alive\r\n" |
| 7430 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7431 | }; |
| 7432 | |
| 7433 | MockRead data_reads2[] = { |
| 7434 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7435 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7436 | MockRead(SYNCHRONOUS, OK), |
| 7437 | }; |
| 7438 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7439 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7440 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7441 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7442 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7443 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7444 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7446 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7447 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7449 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7451 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7452 | |
| 7453 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7454 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7456 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7457 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7460 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7461 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7462 | |
| 7463 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7464 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7465 | |
| 7466 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7467 | |
| 7468 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7469 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7470 | } |
| 7471 | |
| 7472 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7473 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7474 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7475 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7476 | HttpRequestInfo request; |
| 7477 | request.method = "GET"; |
| 7478 | // Note: the URL has a username:password in it. The password "baz" is |
| 7479 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7480 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7481 | |
| 7482 | request.load_flags = LOAD_NORMAL; |
| 7483 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7486 | |
| 7487 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7488 | MockWrite( |
| 7489 | "GET / HTTP/1.1\r\n" |
| 7490 | "Host: www.example.org\r\n" |
| 7491 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7492 | }; |
| 7493 | |
| 7494 | MockRead data_reads1[] = { |
| 7495 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7496 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7497 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7498 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7499 | }; |
| 7500 | |
| 7501 | // After the challenge above, the transaction will be restarted using the |
| 7502 | // identity from the url (foo, baz) to answer the challenge. |
| 7503 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7504 | MockWrite( |
| 7505 | "GET / HTTP/1.1\r\n" |
| 7506 | "Host: www.example.org\r\n" |
| 7507 | "Connection: keep-alive\r\n" |
| 7508 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7509 | }; |
| 7510 | |
| 7511 | MockRead data_reads2[] = { |
| 7512 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7513 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7514 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7515 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7516 | }; |
| 7517 | |
| 7518 | // After the challenge above, the transaction will be restarted using the |
| 7519 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7520 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7521 | MockWrite( |
| 7522 | "GET / HTTP/1.1\r\n" |
| 7523 | "Host: www.example.org\r\n" |
| 7524 | "Connection: keep-alive\r\n" |
| 7525 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7526 | }; |
| 7527 | |
| 7528 | MockRead data_reads3[] = { |
| 7529 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7530 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7531 | MockRead(SYNCHRONOUS, OK), |
| 7532 | }; |
| 7533 | |
| 7534 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7535 | data_writes1, arraysize(data_writes1)); |
| 7536 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7537 | data_writes2, arraysize(data_writes2)); |
| 7538 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7539 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7540 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7541 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7542 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7543 | |
| 7544 | TestCompletionCallback callback1; |
| 7545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7546 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7548 | |
| 7549 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7551 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7552 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7553 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7554 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7556 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7557 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7558 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7560 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7561 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7562 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7563 | |
| 7564 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7565 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7567 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7568 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7569 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7571 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7572 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7573 | |
| 7574 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7575 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7576 | |
| 7577 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7578 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7579 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7580 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7581 | } |
| 7582 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7583 | |
| 7584 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7585 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7586 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7587 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7588 | HttpRequestInfo request; |
| 7589 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7590 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7591 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7592 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7593 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7595 | |
| 7596 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7597 | MockWrite( |
| 7598 | "GET / HTTP/1.1\r\n" |
| 7599 | "Host: www.example.org\r\n" |
| 7600 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7601 | }; |
| 7602 | |
| 7603 | MockRead data_reads1[] = { |
| 7604 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7605 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7606 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7607 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7608 | }; |
| 7609 | |
| 7610 | // After the challenge above, the transaction will be restarted using the |
| 7611 | // identity supplied by the user, not the one in the URL, to answer the |
| 7612 | // challenge. |
| 7613 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7614 | MockWrite( |
| 7615 | "GET / HTTP/1.1\r\n" |
| 7616 | "Host: www.example.org\r\n" |
| 7617 | "Connection: keep-alive\r\n" |
| 7618 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7619 | }; |
| 7620 | |
| 7621 | MockRead data_reads3[] = { |
| 7622 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7623 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7624 | MockRead(SYNCHRONOUS, OK), |
| 7625 | }; |
| 7626 | |
| 7627 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7628 | data_writes1, arraysize(data_writes1)); |
| 7629 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7630 | data_writes3, arraysize(data_writes3)); |
| 7631 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7632 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7633 | |
| 7634 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7635 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7637 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7638 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7639 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7641 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7642 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7643 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7644 | |
| 7645 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7646 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7648 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7649 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7650 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7652 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7653 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7654 | |
| 7655 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7656 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7657 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7658 | |
| 7659 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7660 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7661 | } |
| 7662 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7663 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7664 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7666 | |
| 7667 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7668 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7669 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7670 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7671 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7674 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7675 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7676 | MockWrite( |
| 7677 | "GET /x/y/z HTTP/1.1\r\n" |
| 7678 | "Host: www.example.org\r\n" |
| 7679 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7680 | }; |
| 7681 | |
| 7682 | MockRead data_reads1[] = { |
| 7683 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7684 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7685 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7686 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7687 | }; |
| 7688 | |
| 7689 | // Resend with authorization (username=foo, password=bar) |
| 7690 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7691 | MockWrite( |
| 7692 | "GET /x/y/z HTTP/1.1\r\n" |
| 7693 | "Host: www.example.org\r\n" |
| 7694 | "Connection: keep-alive\r\n" |
| 7695 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7696 | }; |
| 7697 | |
| 7698 | // Sever accepts the authorization. |
| 7699 | MockRead data_reads2[] = { |
| 7700 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7703 | }; |
| 7704 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7705 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7706 | data_writes1, arraysize(data_writes1)); |
| 7707 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7708 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7709 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7710 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7711 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7712 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7713 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7714 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7716 | |
| 7717 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7718 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7720 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7721 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7722 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7723 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7724 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7726 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7727 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7728 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7729 | |
| 7730 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7731 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7733 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7734 | ASSERT_TRUE(response); |
| 7735 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7736 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7737 | } |
| 7738 | |
| 7739 | // ------------------------------------------------------------------------ |
| 7740 | |
| 7741 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7742 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7743 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7744 | request.method = "GET"; |
| 7745 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7746 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7747 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7750 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7751 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7752 | MockWrite( |
| 7753 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7754 | "Host: www.example.org\r\n" |
| 7755 | "Connection: keep-alive\r\n" |
| 7756 | // Send preemptive authorization for MyRealm1 |
| 7757 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7758 | }; |
| 7759 | |
| 7760 | // The server didn't like the preemptive authorization, and |
| 7761 | // challenges us for a different realm (MyRealm2). |
| 7762 | MockRead data_reads1[] = { |
| 7763 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7764 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7765 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7766 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7767 | }; |
| 7768 | |
| 7769 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7770 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7771 | MockWrite( |
| 7772 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7773 | "Host: www.example.org\r\n" |
| 7774 | "Connection: keep-alive\r\n" |
| 7775 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7776 | }; |
| 7777 | |
| 7778 | // Sever accepts the authorization. |
| 7779 | MockRead data_reads2[] = { |
| 7780 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7781 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7783 | }; |
| 7784 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7785 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7786 | data_writes1, arraysize(data_writes1)); |
| 7787 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7788 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7789 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7790 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7792 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7794 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7796 | |
| 7797 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7798 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7800 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7801 | ASSERT_TRUE(response); |
| 7802 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7803 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7804 | EXPECT_EQ("http://www.example.org", |
| 7805 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7806 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7807 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7809 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7811 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7812 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7814 | |
| 7815 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7817 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7818 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7819 | ASSERT_TRUE(response); |
| 7820 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7821 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7822 | } |
| 7823 | |
| 7824 | // ------------------------------------------------------------------------ |
| 7825 | |
| 7826 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7827 | // succeed with preemptive authorization. |
| 7828 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7829 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7831 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7833 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7834 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7835 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7836 | MockWrite( |
| 7837 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7838 | "Host: www.example.org\r\n" |
| 7839 | "Connection: keep-alive\r\n" |
| 7840 | // The authorization for MyRealm1 gets sent preemptively |
| 7841 | // (since the url is in the same protection space) |
| 7842 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7843 | }; |
| 7844 | |
| 7845 | // Sever accepts the preemptive authorization |
| 7846 | MockRead data_reads1[] = { |
| 7847 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7848 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7849 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7850 | }; |
| 7851 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7852 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7853 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7854 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7855 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7856 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7857 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7858 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7859 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7860 | |
| 7861 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7862 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7863 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7864 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7865 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7866 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7867 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7868 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7869 | } |
| 7870 | |
| 7871 | // ------------------------------------------------------------------------ |
| 7872 | |
| 7873 | // Transaction 4: request another URL in MyRealm (however the |
| 7874 | // url is not known to belong to the protection space, so no pre-auth). |
| 7875 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7876 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7878 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7881 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7882 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7883 | MockWrite( |
| 7884 | "GET /x/1 HTTP/1.1\r\n" |
| 7885 | "Host: www.example.org\r\n" |
| 7886 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7887 | }; |
| 7888 | |
| 7889 | MockRead data_reads1[] = { |
| 7890 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7891 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7892 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7893 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7894 | }; |
| 7895 | |
| 7896 | // Resend with authorization from MyRealm's cache. |
| 7897 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7898 | MockWrite( |
| 7899 | "GET /x/1 HTTP/1.1\r\n" |
| 7900 | "Host: www.example.org\r\n" |
| 7901 | "Connection: keep-alive\r\n" |
| 7902 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7903 | }; |
| 7904 | |
| 7905 | // Sever accepts the authorization. |
| 7906 | MockRead data_reads2[] = { |
| 7907 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7908 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7909 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7910 | }; |
| 7911 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7912 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7913 | data_writes1, arraysize(data_writes1)); |
| 7914 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7915 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7916 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7917 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7918 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7919 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7921 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7923 | |
| 7924 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7925 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7927 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7928 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7929 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7931 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7932 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7933 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7935 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7936 | ASSERT_TRUE(response); |
| 7937 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7938 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7939 | } |
| 7940 | |
| 7941 | // ------------------------------------------------------------------------ |
| 7942 | |
| 7943 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7944 | // cached identity. Should invalidate and re-prompt. |
| 7945 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7946 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7947 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7948 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7951 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7952 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7953 | MockWrite( |
| 7954 | "GET /p/q/t HTTP/1.1\r\n" |
| 7955 | "Host: www.example.org\r\n" |
| 7956 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7957 | }; |
| 7958 | |
| 7959 | MockRead data_reads1[] = { |
| 7960 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7961 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7962 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7963 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7964 | }; |
| 7965 | |
| 7966 | // Resend with authorization from cache for MyRealm. |
| 7967 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7968 | MockWrite( |
| 7969 | "GET /p/q/t HTTP/1.1\r\n" |
| 7970 | "Host: www.example.org\r\n" |
| 7971 | "Connection: keep-alive\r\n" |
| 7972 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7973 | }; |
| 7974 | |
| 7975 | // Sever rejects the authorization. |
| 7976 | MockRead data_reads2[] = { |
| 7977 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7978 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7979 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7980 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7981 | }; |
| 7982 | |
| 7983 | // At this point we should prompt for new credentials for MyRealm. |
| 7984 | // Restart with username=foo3, password=foo4. |
| 7985 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7986 | MockWrite( |
| 7987 | "GET /p/q/t HTTP/1.1\r\n" |
| 7988 | "Host: www.example.org\r\n" |
| 7989 | "Connection: keep-alive\r\n" |
| 7990 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7991 | }; |
| 7992 | |
| 7993 | // Sever accepts the authorization. |
| 7994 | MockRead data_reads3[] = { |
| 7995 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7996 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7997 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7998 | }; |
| 7999 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8000 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8001 | data_writes1, arraysize(data_writes1)); |
| 8002 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8003 | data_writes2, arraysize(data_writes2)); |
| 8004 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 8005 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8006 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8007 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8008 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8010 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8012 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8014 | |
| 8015 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8016 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8018 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8019 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8020 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8022 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8023 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8024 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8026 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8027 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8028 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8030 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8031 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8032 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8033 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8035 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8036 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8037 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8039 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8040 | ASSERT_TRUE(response); |
| 8041 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8042 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8043 | } |
| 8044 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8045 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8046 | // Tests that nonce count increments when multiple auth attempts |
| 8047 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8048 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8049 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8050 | new HttpAuthHandlerDigest::Factory(); |
| 8051 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8052 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8053 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8054 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8056 | |
| 8057 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8058 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8059 | HttpRequestInfo request; |
| 8060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8061 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8062 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8063 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8064 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8065 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8066 | MockWrite( |
| 8067 | "GET /x/y/z HTTP/1.1\r\n" |
| 8068 | "Host: www.example.org\r\n" |
| 8069 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8070 | }; |
| 8071 | |
| 8072 | MockRead data_reads1[] = { |
| 8073 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8074 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8075 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8076 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8077 | }; |
| 8078 | |
| 8079 | // Resend with authorization (username=foo, password=bar) |
| 8080 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8081 | MockWrite( |
| 8082 | "GET /x/y/z HTTP/1.1\r\n" |
| 8083 | "Host: www.example.org\r\n" |
| 8084 | "Connection: keep-alive\r\n" |
| 8085 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8086 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8087 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8088 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8089 | }; |
| 8090 | |
| 8091 | // Sever accepts the authorization. |
| 8092 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8093 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8094 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8095 | }; |
| 8096 | |
| 8097 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8098 | data_writes1, arraysize(data_writes1)); |
| 8099 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 8100 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8101 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8102 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8103 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8104 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8105 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8106 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8108 | |
| 8109 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8112 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8113 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8114 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8116 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8118 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8119 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8121 | |
| 8122 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8123 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8124 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8125 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8126 | ASSERT_TRUE(response); |
| 8127 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8128 | } |
| 8129 | |
| 8130 | // ------------------------------------------------------------------------ |
| 8131 | |
| 8132 | // Transaction 2: Request another resource in digestive's protection space. |
| 8133 | // This will preemptively add an Authorization header which should have an |
| 8134 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8135 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8136 | HttpRequestInfo request; |
| 8137 | request.method = "GET"; |
| 8138 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8139 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8140 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8143 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8144 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8145 | MockWrite( |
| 8146 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8147 | "Host: www.example.org\r\n" |
| 8148 | "Connection: keep-alive\r\n" |
| 8149 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8150 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8151 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8152 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8153 | }; |
| 8154 | |
| 8155 | // Sever accepts the authorization. |
| 8156 | MockRead data_reads1[] = { |
| 8157 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8158 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8159 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8160 | }; |
| 8161 | |
| 8162 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 8163 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8164 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8166 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8167 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8168 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8169 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8170 | |
| 8171 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8172 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8174 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8175 | ASSERT_TRUE(response); |
| 8176 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8177 | } |
| 8178 | } |
| 8179 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8180 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8181 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8182 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8183 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8184 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8185 | |
| 8186 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8187 | trans.read_buf_ = new IOBuffer(15); |
| 8188 | trans.read_buf_len_ = 15; |
| 8189 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8190 | |
| 8191 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8192 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8193 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8194 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8195 | response->response_time = base::Time::Now(); |
| 8196 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8197 | |
| 8198 | { // Setup state for response_.vary_data |
| 8199 | HttpRequestInfo request; |
| 8200 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8201 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8202 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8203 | request.extra_headers.SetHeader("Foo", "1"); |
| 8204 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8205 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8206 | } |
| 8207 | |
| 8208 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8209 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8210 | |
| 8211 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8212 | EXPECT_FALSE(trans.read_buf_); |
| 8213 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8214 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8215 | EXPECT_FALSE(response->auth_challenge); |
| 8216 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8217 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8218 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8219 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8220 | } |
| 8221 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8222 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8223 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8224 | HttpRequestInfo request; |
| 8225 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8226 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8227 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8229 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8230 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8231 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8232 | MockWrite( |
| 8233 | "GET / HTTP/1.1\r\n" |
| 8234 | "Host: www.example.org\r\n" |
| 8235 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8236 | }; |
| 8237 | |
| 8238 | MockRead data_reads[] = { |
| 8239 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8240 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8241 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8242 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8243 | }; |
| 8244 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8245 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8246 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8247 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8248 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8249 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8250 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8251 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8252 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8253 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8256 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8257 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8258 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8260 | |
| 8261 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8262 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8264 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8266 | |
| 8267 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8268 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8270 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8271 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8272 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8273 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8274 | } |
| 8275 | |
| 8276 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8277 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8278 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8279 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8280 | |
| 8281 | HttpRequestInfo request; |
| 8282 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8283 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8284 | |
| 8285 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8286 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8287 | "Host: www.example.org:443\r\n" |
| 8288 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8289 | }; |
| 8290 | |
| 8291 | MockRead proxy_reads[] = { |
| 8292 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8293 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8294 | }; |
| 8295 | |
| 8296 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8297 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8298 | "Host: www.example.org:443\r\n" |
| 8299 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8300 | MockWrite("GET / HTTP/1.1\r\n" |
| 8301 | "Host: www.example.org\r\n" |
| 8302 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8303 | }; |
| 8304 | |
| 8305 | MockRead data_reads[] = { |
| 8306 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8307 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8308 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8309 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8310 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8311 | }; |
| 8312 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8313 | StaticSocketDataProvider ssl_bad_certificate( |
| 8314 | proxy_reads, arraysize(proxy_reads), |
| 8315 | proxy_writes, arraysize(proxy_writes)); |
| 8316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8317 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8318 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8319 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8320 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8321 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8322 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8323 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8325 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8326 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8327 | |
| 8328 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8329 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8330 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8332 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8333 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8334 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8335 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8336 | |
| 8337 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8338 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8340 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8342 | |
| 8343 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8344 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8346 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8347 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8348 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8349 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8350 | } |
| 8351 | } |
| 8352 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8353 | |
| 8354 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8355 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8356 | session_deps_.proxy_service = |
| 8357 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8358 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8359 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8360 | |
| 8361 | HttpRequestInfo request; |
| 8362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8363 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8364 | |
| 8365 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8366 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8367 | "Host: www.example.org:443\r\n" |
| 8368 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8369 | MockWrite("GET / HTTP/1.1\r\n" |
| 8370 | "Host: www.example.org\r\n" |
| 8371 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8372 | }; |
| 8373 | |
| 8374 | MockRead data_reads[] = { |
| 8375 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8376 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8377 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8378 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8379 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8380 | }; |
| 8381 | |
| 8382 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8383 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8384 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8385 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8386 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8389 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8391 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8396 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8398 | |
| 8399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8400 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8401 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8402 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8403 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8404 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8405 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8406 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8407 | EXPECT_EQ(200, response->headers->response_code()); |
| 8408 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8409 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8410 | |
| 8411 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8412 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8413 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8414 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8415 | } |
| 8416 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8417 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8418 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8419 | session_deps_.proxy_service = |
| 8420 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8421 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8422 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8423 | |
| 8424 | HttpRequestInfo request; |
| 8425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8426 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8427 | |
| 8428 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8429 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8430 | "Host: www.example.org:443\r\n" |
| 8431 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8432 | }; |
| 8433 | |
| 8434 | MockRead data_reads[] = { |
| 8435 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8436 | MockRead("Location: http://login.example.com/\r\n"), |
| 8437 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8439 | }; |
| 8440 | |
| 8441 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8442 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8443 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8444 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8445 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8448 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8452 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8453 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8455 | |
| 8456 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8457 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8459 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8460 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8461 | |
| 8462 | EXPECT_EQ(302, response->headers->response_code()); |
| 8463 | std::string url; |
| 8464 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8465 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8466 | |
| 8467 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8468 | // timing for the proxy connection instead of the connection to the host, |
| 8469 | // and no send / receive times. |
| 8470 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8471 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8472 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8473 | |
| 8474 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8475 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8476 | |
| 8477 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8478 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8479 | load_timing_info.proxy_resolve_end); |
| 8480 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8481 | load_timing_info.connect_timing.connect_start); |
| 8482 | ExpectConnectTimingHasTimes( |
| 8483 | load_timing_info.connect_timing, |
| 8484 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8485 | |
| 8486 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8487 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8488 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8489 | } |
| 8490 | |
| 8491 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8492 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8493 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8494 | |
| 8495 | HttpRequestInfo request; |
| 8496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8497 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8498 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8499 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8500 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8501 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8502 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8503 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8504 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8505 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8506 | }; |
| 8507 | |
| 8508 | static const char* const kExtraHeaders[] = { |
| 8509 | "location", |
| 8510 | "http://login.example.com/", |
| 8511 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8512 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8513 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8514 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8515 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8516 | }; |
| 8517 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8518 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8519 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8520 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8521 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8522 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8523 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8524 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8525 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8526 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8527 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8529 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8531 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8533 | |
| 8534 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8535 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8536 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8537 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8538 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8539 | |
| 8540 | EXPECT_EQ(302, response->headers->response_code()); |
| 8541 | std::string url; |
| 8542 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8543 | EXPECT_EQ("http://login.example.com/", url); |
| 8544 | } |
| 8545 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8546 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8547 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8548 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8549 | |
| 8550 | HttpRequestInfo request; |
| 8551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8552 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8553 | |
| 8554 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8555 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8556 | "Host: www.example.org:443\r\n" |
| 8557 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8558 | }; |
| 8559 | |
| 8560 | MockRead data_reads[] = { |
| 8561 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8562 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8563 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8564 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8565 | }; |
| 8566 | |
| 8567 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8568 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8569 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8570 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8571 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8574 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8575 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8577 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8578 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8579 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8581 | |
| 8582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8583 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8584 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8585 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8586 | } |
| 8587 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8588 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8589 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8590 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8591 | |
| 8592 | HttpRequestInfo request; |
| 8593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8594 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8595 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8596 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8597 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8598 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8599 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8600 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8601 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8602 | }; |
| 8603 | |
| 8604 | static const char* const kExtraHeaders[] = { |
| 8605 | "location", |
| 8606 | "http://login.example.com/", |
| 8607 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8608 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8609 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8610 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8611 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8612 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8613 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8614 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8615 | }; |
| 8616 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8617 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8618 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8619 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8620 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8621 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8625 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8632 | |
| 8633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8634 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8635 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8636 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8637 | } |
| 8638 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8639 | // Test the request-challenge-retry sequence for basic auth, through |
| 8640 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8641 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8642 | HttpRequestInfo request; |
| 8643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8644 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8645 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8646 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8647 | |
| 8648 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8649 | session_deps_.proxy_service = |
| 8650 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8651 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8652 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8654 | |
| 8655 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8656 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8657 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8658 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8659 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8660 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8661 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8663 | // be issuing -- the final header line contains the credentials. |
| 8664 | const char* const kAuthCredentials[] = { |
| 8665 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8666 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8667 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8668 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8669 | HostPortPair("www.example.org", 443))); |
| 8670 | // fetch https://www.example.org/ via HTTP |
| 8671 | const char get[] = |
| 8672 | "GET / HTTP/1.1\r\n" |
| 8673 | "Host: www.example.org\r\n" |
| 8674 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8675 | SpdySerializedFrame wrapped_get( |
| 8676 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8677 | |
| 8678 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8679 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8680 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8681 | }; |
| 8682 | |
| 8683 | // The proxy responds to the connect with a 407, using a persistent |
| 8684 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8685 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8686 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8687 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8688 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8689 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8690 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8691 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8692 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8693 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8694 | "Content-Length: 5\r\n\r\n"; |
| 8695 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8696 | SpdySerializedFrame wrapped_get_resp( |
| 8697 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8698 | SpdySerializedFrame wrapped_body( |
| 8699 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8700 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8701 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8702 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8703 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8704 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8705 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8706 | }; |
| 8707 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8708 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8709 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8710 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8711 | // Negotiate SPDY to the proxy |
| 8712 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8713 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8715 | // Vanilla SSL to the server |
| 8716 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8718 | |
| 8719 | TestCompletionCallback callback1; |
| 8720 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8721 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8722 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8723 | |
| 8724 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8726 | |
| 8727 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8728 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8729 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8730 | log.GetEntries(&entries); |
| 8731 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8732 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8733 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8734 | ExpectLogContainsSomewhere( |
| 8735 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8736 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8737 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8738 | |
| 8739 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8740 | ASSERT_TRUE(response); |
| 8741 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8742 | EXPECT_EQ(407, response->headers->response_code()); |
| 8743 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8744 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8745 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8746 | |
| 8747 | TestCompletionCallback callback2; |
| 8748 | |
| 8749 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8750 | callback2.callback()); |
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 = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8754 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8755 | |
| 8756 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8757 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8758 | |
| 8759 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8760 | EXPECT_EQ(200, response->headers->response_code()); |
| 8761 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8762 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8763 | |
| 8764 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8765 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8766 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8767 | LoadTimingInfo load_timing_info; |
| 8768 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8769 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8770 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8771 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8772 | trans.reset(); |
| 8773 | session->CloseAllConnections(); |
| 8774 | } |
| 8775 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8776 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8777 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8778 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8779 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8780 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8781 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8782 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8783 | HttpRequestInfo request; |
| 8784 | HttpRequestInfo push_request; |
| 8785 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8786 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8787 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8788 | push_request.method = "GET"; |
| 8789 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8790 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8791 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8792 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8793 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8794 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8795 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8796 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8797 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8800 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8801 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8802 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8803 | SpdySerializedFrame stream2_priority( |
| 8804 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8805 | |
| 8806 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8807 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8808 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8809 | }; |
| 8810 | |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8811 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
| 8812 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 8813 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8814 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8815 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8816 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8817 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8818 | |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8819 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8820 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8821 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8822 | |
| 8823 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 8824 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 8825 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8826 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8827 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8828 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8829 | }; |
| 8830 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8831 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8832 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8833 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8834 | // Negotiate SPDY to the proxy |
| 8835 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8836 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8838 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8839 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8840 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8841 | TestCompletionCallback callback; |
| 8842 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8844 | |
| 8845 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8846 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8847 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8848 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8849 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8850 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8851 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8853 | |
| 8854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8856 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8857 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8858 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8859 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8860 | |
| 8861 | EXPECT_EQ(200, response->headers->response_code()); |
| 8862 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8863 | |
| 8864 | std::string response_data; |
| 8865 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8867 | EXPECT_EQ("hello!", response_data); |
| 8868 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8869 | LoadTimingInfo load_timing_info; |
| 8870 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8871 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8872 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8873 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8874 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8875 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8876 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8877 | |
| 8878 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8880 | EXPECT_EQ("pushed", response_data); |
| 8881 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8882 | LoadTimingInfo push_load_timing_info; |
| 8883 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8884 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8885 | // The transactions should share a socket ID, despite being for different |
| 8886 | // origins. |
| 8887 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8888 | push_load_timing_info.socket_log_id); |
| 8889 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8890 | trans.reset(); |
| 8891 | push_trans.reset(); |
| 8892 | session->CloseAllConnections(); |
| 8893 | } |
| 8894 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8895 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8896 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8897 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8898 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8899 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8900 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8901 | HttpRequestInfo request; |
| 8902 | |
| 8903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8904 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8905 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8906 | session_deps_.proxy_service = |
| 8907 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8908 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8909 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8910 | |
| 8911 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8912 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8915 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8916 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8917 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8918 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8919 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8920 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8921 | |
| 8922 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8923 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8924 | }; |
| 8925 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8926 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8927 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8928 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8929 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8930 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8931 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8932 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8933 | |
| 8934 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8935 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8936 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8937 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8938 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8939 | }; |
| 8940 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8941 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8942 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8943 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8944 | // Negotiate SPDY to the proxy |
| 8945 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8946 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8948 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8949 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8950 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8951 | TestCompletionCallback callback; |
| 8952 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8954 | |
| 8955 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8956 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8957 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8958 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8959 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8960 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8961 | |
| 8962 | EXPECT_EQ(200, response->headers->response_code()); |
| 8963 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8964 | |
| 8965 | std::string response_data; |
| 8966 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8967 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8968 | EXPECT_EQ("hello!", response_data); |
| 8969 | |
| 8970 | trans.reset(); |
| 8971 | session->CloseAllConnections(); |
| 8972 | } |
| 8973 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8974 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8975 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8976 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8977 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8978 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8979 | proxy_delegate->set_trusted_spdy_proxy( |
| 8980 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8981 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8982 | HttpRequestInfo request; |
| 8983 | |
| 8984 | request.method = "GET"; |
| 8985 | request.url = GURL("http://www.example.org/"); |
| 8986 | |
| 8987 | // Configure against https proxy server "myproxy:70". |
| 8988 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8989 | BoundTestNetLog log; |
| 8990 | session_deps_.net_log = log.bound().net_log(); |
| 8991 | |
| 8992 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8993 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8996 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8997 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8998 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8999 | SpdySerializedFrame stream2_priority( |
| 9000 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9001 | |
| 9002 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9003 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9004 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9005 | }; |
| 9006 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9007 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9008 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9009 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9010 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9011 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9012 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9013 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9014 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9015 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9016 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9017 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9018 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9019 | |
| 9020 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9021 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9022 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9023 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9024 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9025 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9026 | }; |
| 9027 | |
| 9028 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 9029 | arraysize(spdy_writes)); |
| 9030 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9031 | // Negotiate SPDY to the proxy |
| 9032 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9033 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9035 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9036 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9037 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9038 | TestCompletionCallback callback; |
| 9039 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9041 | |
| 9042 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9043 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9044 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9045 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9046 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9047 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9048 | |
| 9049 | EXPECT_EQ(200, response->headers->response_code()); |
| 9050 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9051 | |
| 9052 | std::string response_data; |
| 9053 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9054 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9055 | EXPECT_EQ("hello!", response_data); |
| 9056 | |
| 9057 | trans.reset(); |
| 9058 | session->CloseAllConnections(); |
| 9059 | } |
| 9060 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9061 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9062 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9063 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9064 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9065 | |
| 9066 | HttpRequestInfo request; |
| 9067 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9069 | |
| 9070 | // Attempt to fetch the URL from a server with a bad cert |
| 9071 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9072 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9073 | "Host: www.example.org:443\r\n" |
| 9074 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9075 | }; |
| 9076 | |
| 9077 | MockRead bad_cert_reads[] = { |
| 9078 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9079 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9080 | }; |
| 9081 | |
| 9082 | // Attempt to fetch the URL with a good cert |
| 9083 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9084 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9085 | "Host: www.example.org:443\r\n" |
| 9086 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9087 | MockWrite("GET / HTTP/1.1\r\n" |
| 9088 | "Host: www.example.org\r\n" |
| 9089 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9090 | }; |
| 9091 | |
| 9092 | MockRead good_cert_reads[] = { |
| 9093 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9094 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9095 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9096 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9097 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9098 | }; |
| 9099 | |
| 9100 | StaticSocketDataProvider ssl_bad_certificate( |
| 9101 | bad_cert_reads, arraysize(bad_cert_reads), |
| 9102 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 9103 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 9104 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9105 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9106 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9107 | |
| 9108 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9109 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9110 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9111 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9112 | |
| 9113 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9116 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9117 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9118 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9119 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9122 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9123 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9125 | |
| 9126 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9127 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9131 | |
| 9132 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9133 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9136 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9137 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9138 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9139 | } |
| 9140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9141 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9142 | HttpRequestInfo request; |
| 9143 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9144 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9145 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9146 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9150 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9151 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9152 | MockWrite( |
| 9153 | "GET / HTTP/1.1\r\n" |
| 9154 | "Host: www.example.org\r\n" |
| 9155 | "Connection: keep-alive\r\n" |
| 9156 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9157 | }; |
| 9158 | |
| 9159 | // Lastly, the server responds with the actual content. |
| 9160 | MockRead data_reads[] = { |
| 9161 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9162 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9163 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9164 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9165 | }; |
| 9166 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9167 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9168 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9169 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9171 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9172 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9173 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9175 | |
| 9176 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9177 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9178 | } |
| 9179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9180 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9181 | HttpRequestInfo request; |
| 9182 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9183 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9184 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9185 | "Chromium Ultra Awesome X Edition"); |
| 9186 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9187 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9189 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9190 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9191 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9192 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9193 | "Host: www.example.org:443\r\n" |
| 9194 | "Proxy-Connection: keep-alive\r\n" |
| 9195 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9196 | }; |
| 9197 | MockRead data_reads[] = { |
| 9198 | // Return an error, so the transaction stops here (this test isn't |
| 9199 | // interested in the rest). |
| 9200 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9201 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9202 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9203 | }; |
| 9204 | |
| 9205 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9206 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9207 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9208 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9209 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9210 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9211 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9212 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9213 | |
| 9214 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9215 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9216 | } |
| 9217 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9218 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9219 | HttpRequestInfo request; |
| 9220 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9221 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9222 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9223 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9227 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9228 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9229 | MockWrite( |
| 9230 | "GET / HTTP/1.1\r\n" |
| 9231 | "Host: www.example.org\r\n" |
| 9232 | "Connection: keep-alive\r\n" |
| 9233 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9234 | }; |
| 9235 | |
| 9236 | // Lastly, the server responds with the actual content. |
| 9237 | MockRead data_reads[] = { |
| 9238 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9239 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9240 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9242 | }; |
| 9243 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9244 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9245 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9246 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9248 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9249 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9250 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9252 | |
| 9253 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9255 | } |
| 9256 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9257 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9258 | HttpRequestInfo request; |
| 9259 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9260 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9261 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9263 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9264 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9265 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9266 | MockWrite( |
| 9267 | "POST / HTTP/1.1\r\n" |
| 9268 | "Host: www.example.org\r\n" |
| 9269 | "Connection: keep-alive\r\n" |
| 9270 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9271 | }; |
| 9272 | |
| 9273 | // Lastly, the server responds with the actual content. |
| 9274 | MockRead data_reads[] = { |
| 9275 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9276 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9277 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9278 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9279 | }; |
| 9280 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9281 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9282 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9283 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9284 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9285 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9287 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9289 | |
| 9290 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9291 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9292 | } |
| 9293 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9294 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9295 | HttpRequestInfo request; |
| 9296 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9297 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9298 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9301 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9302 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9303 | MockWrite( |
| 9304 | "PUT / HTTP/1.1\r\n" |
| 9305 | "Host: www.example.org\r\n" |
| 9306 | "Connection: keep-alive\r\n" |
| 9307 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9308 | }; |
| 9309 | |
| 9310 | // Lastly, the server responds with the actual content. |
| 9311 | MockRead data_reads[] = { |
| 9312 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9313 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9314 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9315 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9316 | }; |
| 9317 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9318 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9319 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9321 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9322 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9324 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9326 | |
| 9327 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9329 | } |
| 9330 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9331 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9332 | HttpRequestInfo request; |
| 9333 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9334 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9337 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9338 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9339 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9340 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9341 | "Host: www.example.org\r\n" |
| 9342 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9343 | }; |
| 9344 | |
| 9345 | // Lastly, the server responds with the actual content. |
| 9346 | MockRead data_reads[] = { |
| 9347 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9348 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9349 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9350 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9351 | }; |
| 9352 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9353 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9354 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9357 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9359 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9361 | |
| 9362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9364 | } |
| 9365 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9366 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9367 | HttpRequestInfo request; |
| 9368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9369 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9370 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9371 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9373 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9374 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9375 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9376 | MockWrite( |
| 9377 | "GET / HTTP/1.1\r\n" |
| 9378 | "Host: www.example.org\r\n" |
| 9379 | "Connection: keep-alive\r\n" |
| 9380 | "Pragma: no-cache\r\n" |
| 9381 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9382 | }; |
| 9383 | |
| 9384 | // Lastly, the server responds with the actual content. |
| 9385 | MockRead data_reads[] = { |
| 9386 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9387 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9388 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9389 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9390 | }; |
| 9391 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9392 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9393 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9394 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9395 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9396 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9397 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9398 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9400 | |
| 9401 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9402 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9403 | } |
| 9404 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9405 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9406 | HttpRequestInfo request; |
| 9407 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9408 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9409 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9410 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9411 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9412 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9413 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9414 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9415 | MockWrite( |
| 9416 | "GET / HTTP/1.1\r\n" |
| 9417 | "Host: www.example.org\r\n" |
| 9418 | "Connection: keep-alive\r\n" |
| 9419 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9420 | }; |
| 9421 | |
| 9422 | // Lastly, the server responds with the actual content. |
| 9423 | MockRead data_reads[] = { |
| 9424 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9425 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9426 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9427 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9428 | }; |
| 9429 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9430 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9431 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9432 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9434 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9438 | |
| 9439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9441 | } |
| 9442 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9443 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9444 | HttpRequestInfo request; |
| 9445 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9446 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9447 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9448 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9449 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9450 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9451 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9452 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9453 | MockWrite( |
| 9454 | "GET / HTTP/1.1\r\n" |
| 9455 | "Host: www.example.org\r\n" |
| 9456 | "Connection: keep-alive\r\n" |
| 9457 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9458 | }; |
| 9459 | |
| 9460 | // Lastly, the server responds with the actual content. |
| 9461 | MockRead data_reads[] = { |
| 9462 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9463 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9464 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9465 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9466 | }; |
| 9467 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9468 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9469 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9470 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9472 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9476 | |
| 9477 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9479 | } |
| 9480 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9481 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9482 | HttpRequestInfo request; |
| 9483 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9484 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9485 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9486 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9487 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9488 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9489 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9490 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9491 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9492 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9493 | MockWrite( |
| 9494 | "GET / HTTP/1.1\r\n" |
| 9495 | "Host: www.example.org\r\n" |
| 9496 | "Connection: keep-alive\r\n" |
| 9497 | "referer: www.foo.com\r\n" |
| 9498 | "hEllo: Kitty\r\n" |
| 9499 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9500 | }; |
| 9501 | |
| 9502 | // Lastly, the server responds with the actual content. |
| 9503 | MockRead data_reads[] = { |
| 9504 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9505 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9506 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9508 | }; |
| 9509 | |
| 9510 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9511 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9514 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9515 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9516 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9518 | |
| 9519 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9520 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9521 | } |
| 9522 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9523 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9524 | HttpRequestInfo request; |
| 9525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9526 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9527 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9528 | session_deps_.proxy_service = |
| 9529 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9530 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9531 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9532 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9535 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9536 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9537 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9538 | |
| 9539 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9540 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9541 | MockWrite( |
| 9542 | "GET / HTTP/1.1\r\n" |
| 9543 | "Host: www.example.org\r\n" |
| 9544 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9545 | |
| 9546 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9547 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9548 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9549 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9550 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9551 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9552 | }; |
| 9553 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9554 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9555 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9558 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9560 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9562 | |
| 9563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9564 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9566 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9567 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9568 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9569 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9570 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9571 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9572 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9573 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9574 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9575 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9576 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9578 | EXPECT_EQ("Payload", response_text); |
| 9579 | } |
| 9580 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9581 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9582 | HttpRequestInfo request; |
| 9583 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9584 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9585 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9586 | session_deps_.proxy_service = |
| 9587 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9588 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9589 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9590 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9591 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9592 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9593 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9594 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9595 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9596 | |
| 9597 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9598 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9599 | arraysize(write_buffer)), |
| 9600 | MockWrite( |
| 9601 | "GET / HTTP/1.1\r\n" |
| 9602 | "Host: www.example.org\r\n" |
| 9603 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9604 | |
| 9605 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9606 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9607 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9608 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9609 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9610 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9611 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9612 | }; |
| 9613 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9614 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9615 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9616 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9617 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9618 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9621 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9625 | |
| 9626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9628 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9629 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9630 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9631 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9632 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9635 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9636 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9637 | |
| 9638 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9639 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9641 | EXPECT_EQ("Payload", response_text); |
| 9642 | } |
| 9643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9644 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9645 | HttpRequestInfo request; |
| 9646 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9647 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9648 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9649 | session_deps_.proxy_service = |
| 9650 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9651 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9652 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9653 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9656 | |
| 9657 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9658 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9659 | |
| 9660 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9661 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9662 | MockWrite( |
| 9663 | "GET / HTTP/1.1\r\n" |
| 9664 | "Host: www.example.org\r\n" |
| 9665 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9666 | |
| 9667 | MockRead data_reads[] = { |
| 9668 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9669 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9670 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9671 | MockRead("Payload"), |
| 9672 | MockRead(SYNCHRONOUS, OK) |
| 9673 | }; |
| 9674 | |
| 9675 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9676 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9677 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9678 | |
| 9679 | TestCompletionCallback callback; |
| 9680 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9681 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9682 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9683 | |
| 9684 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9685 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9687 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9688 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9689 | |
| 9690 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9691 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9692 | TestLoadTimingNotReused(load_timing_info, |
| 9693 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9694 | |
| 9695 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9696 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9697 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9698 | EXPECT_EQ("Payload", response_text); |
| 9699 | } |
| 9700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9701 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9702 | HttpRequestInfo request; |
| 9703 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9704 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9705 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9706 | session_deps_.proxy_service = |
| 9707 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9708 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9709 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9710 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9711 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9713 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9714 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9715 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9716 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9717 | 0x05, // Version |
| 9718 | 0x01, // Command (CONNECT) |
| 9719 | 0x00, // Reserved. |
| 9720 | 0x03, // Address type (DOMAINNAME). |
| 9721 | 0x0F, // Length of domain (15) |
| 9722 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9723 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9724 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9725 | const char kSOCKS5OkResponse[] = |
| 9726 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9727 | |
| 9728 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9729 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9730 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9731 | MockWrite( |
| 9732 | "GET / HTTP/1.1\r\n" |
| 9733 | "Host: www.example.org\r\n" |
| 9734 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9735 | |
| 9736 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9737 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9738 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9739 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9740 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9741 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9742 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9743 | }; |
| 9744 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9745 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9746 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9747 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9748 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9749 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9750 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9751 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9753 | |
| 9754 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9755 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9757 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9758 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9759 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9760 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9761 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9762 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9763 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9764 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9765 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9766 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9767 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9768 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9769 | EXPECT_EQ("Payload", response_text); |
| 9770 | } |
| 9771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9772 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9773 | HttpRequestInfo request; |
| 9774 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9775 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9776 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9777 | session_deps_.proxy_service = |
| 9778 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9779 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9780 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9784 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9785 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9786 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9787 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9788 | 0x05, // Version |
| 9789 | 0x01, // Command (CONNECT) |
| 9790 | 0x00, // Reserved. |
| 9791 | 0x03, // Address type (DOMAINNAME). |
| 9792 | 0x0F, // Length of domain (15) |
| 9793 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9794 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9795 | }; |
| 9796 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9797 | const char kSOCKS5OkResponse[] = |
| 9798 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9799 | |
| 9800 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9801 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9802 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9803 | arraysize(kSOCKS5OkRequest)), |
| 9804 | MockWrite( |
| 9805 | "GET / HTTP/1.1\r\n" |
| 9806 | "Host: www.example.org\r\n" |
| 9807 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9808 | |
| 9809 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9810 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9811 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9812 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9813 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9814 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9815 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9816 | }; |
| 9817 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9818 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9819 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9821 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9822 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9823 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9824 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9825 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9829 | |
| 9830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9831 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9834 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9835 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9836 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9837 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9838 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9839 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9840 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9841 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9842 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9843 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9845 | EXPECT_EQ("Payload", response_text); |
| 9846 | } |
| 9847 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9848 | namespace { |
| 9849 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9850 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9851 | |
| 9852 | struct GroupNameTest { |
| 9853 | std::string proxy_server; |
| 9854 | std::string url; |
| 9855 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9856 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9857 | }; |
| 9858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9859 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9860 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9862 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9863 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9864 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9865 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9866 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9867 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9868 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9869 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9870 | |
| 9871 | return session; |
| 9872 | } |
| 9873 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9874 | int GroupNameTransactionHelper(const std::string& url, |
| 9875 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9876 | HttpRequestInfo request; |
| 9877 | request.method = "GET"; |
| 9878 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9882 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9883 | |
| 9884 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9885 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9886 | } |
| 9887 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9888 | } // namespace |
| 9889 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9890 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9891 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9892 | { |
| 9893 | "", // unused |
| 9894 | "http://www.example.org/direct", |
| 9895 | "www.example.org:80", |
| 9896 | false, |
| 9897 | }, |
| 9898 | { |
| 9899 | "", // unused |
| 9900 | "http://[2001:1418:13:1::25]/direct", |
| 9901 | "[2001:1418:13:1::25]:80", |
| 9902 | false, |
| 9903 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9904 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9905 | // SSL Tests |
| 9906 | { |
| 9907 | "", // unused |
| 9908 | "https://www.example.org/direct_ssl", |
| 9909 | "ssl/www.example.org:443", |
| 9910 | true, |
| 9911 | }, |
| 9912 | { |
| 9913 | "", // unused |
| 9914 | "https://[2001:1418:13:1::25]/direct", |
| 9915 | "ssl/[2001:1418:13:1::25]:443", |
| 9916 | true, |
| 9917 | }, |
| 9918 | { |
| 9919 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9920 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9921 | "ssl/host.with.alternate:443", |
| 9922 | true, |
| 9923 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9924 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9925 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9926 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9927 | session_deps_.proxy_service = |
| 9928 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9929 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9930 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9931 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9932 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9933 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9934 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9935 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9936 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9937 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9938 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9939 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9940 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9941 | |
| 9942 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9943 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9944 | if (tests[i].ssl) |
| 9945 | EXPECT_EQ(tests[i].expected_group_name, |
| 9946 | ssl_conn_pool->last_group_name_received()); |
| 9947 | else |
| 9948 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9949 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9950 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9951 | } |
| 9952 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9953 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9954 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9955 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame^] | 9956 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 9957 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9958 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9959 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9960 | // SSL Tests |
| 9961 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame^] | 9962 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 9963 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9964 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9965 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9966 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame^] | 9967 | "http_proxy", "https://host.with.alternate/direct", |
| 9968 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9969 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9970 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9971 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame^] | 9972 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 9973 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9974 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9975 | }; |
| 9976 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9977 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9978 | session_deps_.proxy_service = |
| 9979 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9980 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9981 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9982 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9983 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9984 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9985 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9986 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9987 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9988 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9989 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9990 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9991 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9992 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9993 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9994 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9995 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9996 | |
| 9997 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9998 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9999 | if (tests[i].ssl) |
| 10000 | EXPECT_EQ(tests[i].expected_group_name, |
| 10001 | ssl_conn_pool->last_group_name_received()); |
| 10002 | else |
| 10003 | EXPECT_EQ(tests[i].expected_group_name, |
| 10004 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10005 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10006 | } |
| 10007 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10008 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10009 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10010 | { |
| 10011 | "socks4://socks_proxy:1080", |
| 10012 | "http://www.example.org/socks4_direct", |
| 10013 | "socks4/www.example.org:80", |
| 10014 | false, |
| 10015 | }, |
| 10016 | { |
| 10017 | "socks5://socks_proxy:1080", |
| 10018 | "http://www.example.org/socks5_direct", |
| 10019 | "socks5/www.example.org:80", |
| 10020 | false, |
| 10021 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10022 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10023 | // SSL Tests |
| 10024 | { |
| 10025 | "socks4://socks_proxy:1080", |
| 10026 | "https://www.example.org/socks4_ssl", |
| 10027 | "socks4/ssl/www.example.org:443", |
| 10028 | true, |
| 10029 | }, |
| 10030 | { |
| 10031 | "socks5://socks_proxy:1080", |
| 10032 | "https://www.example.org/socks5_ssl", |
| 10033 | "socks5/ssl/www.example.org:443", |
| 10034 | true, |
| 10035 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10036 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10037 | { |
| 10038 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10039 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10040 | "socks4/ssl/host.with.alternate:443", |
| 10041 | true, |
| 10042 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10043 | }; |
| 10044 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10045 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10046 | session_deps_.proxy_service = |
| 10047 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10048 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10049 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10050 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10051 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10052 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10053 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10054 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10055 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10056 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10057 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10058 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10059 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10060 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10061 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10062 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10063 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10066 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10067 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10068 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10069 | if (tests[i].ssl) |
| 10070 | EXPECT_EQ(tests[i].expected_group_name, |
| 10071 | ssl_conn_pool->last_group_name_received()); |
| 10072 | else |
| 10073 | EXPECT_EQ(tests[i].expected_group_name, |
| 10074 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10075 | } |
| 10076 | } |
| 10077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10078 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10079 | HttpRequestInfo request; |
| 10080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10081 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10082 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10083 | session_deps_.proxy_service = |
| 10084 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10085 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10086 | // This simulates failure resolving all hostnames; that means we will fail |
| 10087 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10088 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10093 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10094 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10095 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10097 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10098 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10099 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10100 | } |
| 10101 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10102 | // Base test to make sure that when the load flags for a request specify to |
| 10103 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 10104 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10105 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10106 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10107 | HttpRequestInfo request_info; |
| 10108 | request_info.method = "GET"; |
| 10109 | request_info.load_flags = load_flags; |
| 10110 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10111 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10112 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10113 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10114 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10117 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10118 | // 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] | 10119 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10120 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10121 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10122 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10123 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10124 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10125 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10127 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10128 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10129 | |
| 10130 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10131 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10132 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10133 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10134 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10135 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10136 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10137 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10138 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10139 | // 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] | 10140 | // we can tell if the next lookup hit the cache, or the "network". |
| 10141 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10142 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10143 | |
| 10144 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10145 | // 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] | 10146 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10147 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10148 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10149 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10150 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10151 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10152 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10153 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10154 | |
| 10155 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10156 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10157 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10158 | } |
| 10159 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10160 | // There are multiple load flags that should trigger the host cache bypass. |
| 10161 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10162 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10163 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 10164 | } |
| 10165 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10166 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10167 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 10168 | } |
| 10169 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10170 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 10171 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 10172 | } |
| 10173 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10174 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10175 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10176 | HttpRequestInfo request; |
| 10177 | request.method = "GET"; |
| 10178 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10179 | |
| 10180 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10181 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10182 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10183 | StaticSocketDataProvider data(NULL, 0, |
| 10184 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10187 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10188 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10190 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10191 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10192 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10193 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10194 | |
| 10195 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10196 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10197 | |
| 10198 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10199 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10200 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10201 | } |
| 10202 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10203 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10204 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10205 | HttpRequestInfo request; |
| 10206 | request.method = "GET"; |
| 10207 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10208 | |
| 10209 | MockRead data_reads[] = { |
| 10210 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10211 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10212 | }; |
| 10213 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10214 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10218 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10221 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10222 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10224 | |
| 10225 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10226 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10228 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10229 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10230 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10231 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10232 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10233 | |
| 10234 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10235 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10236 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10237 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10238 | |
| 10239 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10240 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10241 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10242 | } |
| 10243 | |
| 10244 | // Make sure that a dropped connection while draining the body for auth |
| 10245 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10246 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10247 | HttpRequestInfo request; |
| 10248 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10249 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10250 | |
| 10251 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10252 | MockWrite( |
| 10253 | "GET / HTTP/1.1\r\n" |
| 10254 | "Host: www.example.org\r\n" |
| 10255 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10256 | }; |
| 10257 | |
| 10258 | MockRead data_reads1[] = { |
| 10259 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10260 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10261 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10262 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10263 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10264 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10265 | }; |
| 10266 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10268 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10271 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10272 | // be issuing -- the final header line contains the credentials. |
| 10273 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10274 | MockWrite( |
| 10275 | "GET / HTTP/1.1\r\n" |
| 10276 | "Host: www.example.org\r\n" |
| 10277 | "Connection: keep-alive\r\n" |
| 10278 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10279 | }; |
| 10280 | |
| 10281 | // Lastly, the server responds with the actual content. |
| 10282 | MockRead data_reads2[] = { |
| 10283 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10284 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10285 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10286 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10287 | }; |
| 10288 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10289 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10290 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10291 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10294 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10298 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10300 | |
| 10301 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10305 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10306 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10307 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10308 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10310 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10312 | |
| 10313 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10315 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10316 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10317 | ASSERT_TRUE(response); |
| 10318 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10319 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10320 | } |
| 10321 | |
| 10322 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10323 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10324 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10325 | |
| 10326 | HttpRequestInfo request; |
| 10327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10328 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10329 | |
| 10330 | MockRead proxy_reads[] = { |
| 10331 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10332 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10333 | }; |
| 10334 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10335 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10336 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10337 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10338 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10339 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10341 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10343 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10348 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10350 | |
| 10351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10352 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10353 | } |
| 10354 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10355 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10356 | HttpRequestInfo request; |
| 10357 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10358 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10359 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10362 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10363 | MockRead data_reads[] = { |
| 10364 | 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] | 10365 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10366 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10367 | |
| 10368 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10369 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10370 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10371 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10372 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10373 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10375 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10376 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10378 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10379 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10380 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10381 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10382 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10383 | |
| 10384 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10385 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10386 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10387 | } |
| 10388 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10389 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10390 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10391 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10392 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10393 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10394 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10395 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10396 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10397 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10398 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10399 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10400 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10401 | |
| 10402 | HttpRequestInfo request; |
| 10403 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10404 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10405 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10406 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10409 | |
| 10410 | MockRead data_reads[] = { |
| 10411 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10412 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10413 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10414 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10415 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10416 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10418 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10419 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10420 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10421 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10422 | |
| 10423 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10424 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10425 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10426 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10427 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10428 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10429 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10430 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10431 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10432 | } |
| 10433 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10434 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10435 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10436 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10437 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10438 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10439 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10440 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10441 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10443 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10444 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10445 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10446 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10447 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10448 | |
| 10449 | HttpRequestInfo request; |
| 10450 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10451 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10452 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10453 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10454 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10457 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10458 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10459 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10460 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10461 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10463 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10465 | |
| 10466 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10467 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10468 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10469 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10470 | } |
| 10471 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10472 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10473 | class FakeUploadElementReader : public UploadElementReader { |
| 10474 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10475 | FakeUploadElementReader() = default; |
| 10476 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10477 | |
| 10478 | const CompletionCallback& callback() const { return callback_; } |
| 10479 | |
| 10480 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10481 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10482 | callback_ = callback; |
| 10483 | return ERR_IO_PENDING; |
| 10484 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10485 | uint64_t GetContentLength() const override { return 0; } |
| 10486 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10487 | int Read(IOBuffer* buf, |
| 10488 | int buf_length, |
| 10489 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10490 | return ERR_FAILED; |
| 10491 | } |
| 10492 | |
| 10493 | private: |
| 10494 | CompletionCallback callback_; |
| 10495 | }; |
| 10496 | |
| 10497 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10498 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10499 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10500 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10501 | |
| 10502 | HttpRequestInfo request; |
| 10503 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10504 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10505 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10508 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10509 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10510 | |
| 10511 | StaticSocketDataProvider data; |
| 10512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10513 | |
| 10514 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10515 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10517 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10518 | |
| 10519 | // Transaction is pending on request body initialization. |
| 10520 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10521 | |
| 10522 | // Return Init()'s result after the transaction gets destroyed. |
| 10523 | trans.reset(); |
| 10524 | fake_reader->callback().Run(OK); // Should not crash. |
| 10525 | } |
| 10526 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10527 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10528 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10529 | HttpRequestInfo request; |
| 10530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10531 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10532 | |
| 10533 | // First transaction will request a resource and receive a Basic challenge |
| 10534 | // with realm="first_realm". |
| 10535 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10536 | MockWrite( |
| 10537 | "GET / HTTP/1.1\r\n" |
| 10538 | "Host: www.example.org\r\n" |
| 10539 | "Connection: keep-alive\r\n" |
| 10540 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10541 | }; |
| 10542 | MockRead data_reads1[] = { |
| 10543 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10544 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10545 | "\r\n"), |
| 10546 | }; |
| 10547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10548 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10549 | // for first_realm. The server will reject and provide a challenge with |
| 10550 | // second_realm. |
| 10551 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10552 | MockWrite( |
| 10553 | "GET / HTTP/1.1\r\n" |
| 10554 | "Host: www.example.org\r\n" |
| 10555 | "Connection: keep-alive\r\n" |
| 10556 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10557 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10558 | }; |
| 10559 | MockRead data_reads2[] = { |
| 10560 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10561 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10562 | "\r\n"), |
| 10563 | }; |
| 10564 | |
| 10565 | // This again fails, and goes back to first_realm. Make sure that the |
| 10566 | // entry is removed from cache. |
| 10567 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10568 | MockWrite( |
| 10569 | "GET / HTTP/1.1\r\n" |
| 10570 | "Host: www.example.org\r\n" |
| 10571 | "Connection: keep-alive\r\n" |
| 10572 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10573 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10574 | }; |
| 10575 | MockRead data_reads3[] = { |
| 10576 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10577 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10578 | "\r\n"), |
| 10579 | }; |
| 10580 | |
| 10581 | // Try one last time (with the correct password) and get the resource. |
| 10582 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10583 | MockWrite( |
| 10584 | "GET / HTTP/1.1\r\n" |
| 10585 | "Host: www.example.org\r\n" |
| 10586 | "Connection: keep-alive\r\n" |
| 10587 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10588 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10589 | }; |
| 10590 | MockRead data_reads4[] = { |
| 10591 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10592 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10593 | "Content-Length: 5\r\n" |
| 10594 | "\r\n" |
| 10595 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10596 | }; |
| 10597 | |
| 10598 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10599 | data_writes1, arraysize(data_writes1)); |
| 10600 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10601 | data_writes2, arraysize(data_writes2)); |
| 10602 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10603 | data_writes3, arraysize(data_writes3)); |
| 10604 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10605 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10606 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10607 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10608 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10609 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10610 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10611 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10614 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10615 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10616 | // Issue the first request with Authorize headers. There should be a |
| 10617 | // password prompt for first_realm waiting to be filled in after the |
| 10618 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10619 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10620 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10621 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10622 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10623 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10624 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10625 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10626 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10627 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10628 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10629 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10630 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10631 | |
| 10632 | // Issue the second request with an incorrect password. There should be a |
| 10633 | // password prompt for second_realm waiting to be filled in after the |
| 10634 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10635 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10636 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10637 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10638 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10639 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10640 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10641 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10642 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10643 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10644 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10645 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10646 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10647 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10648 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10649 | |
| 10650 | // Issue the third request with another incorrect password. There should be |
| 10651 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10652 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10653 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10654 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10655 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10656 | callback3.callback()); |
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 = callback3.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 | 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 | 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 fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10670 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10671 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10672 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10674 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10675 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10676 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10677 | ASSERT_TRUE(response); |
| 10678 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10679 | } |
| 10680 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10681 | // Regression test for https://crbug.com/754395. |
| 10682 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10683 | MockRead data_reads[] = { |
| 10684 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10685 | MockRead(kAlternativeServiceHttpHeader), |
| 10686 | MockRead("\r\n"), |
| 10687 | MockRead("hello world"), |
| 10688 | MockRead(SYNCHRONOUS, OK), |
| 10689 | }; |
| 10690 | |
| 10691 | HttpRequestInfo request; |
| 10692 | request.method = "GET"; |
| 10693 | request.url = GURL("https://www.example.org/"); |
| 10694 | |
| 10695 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10696 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10697 | |
| 10698 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10699 | ssl.ssl_info.cert = |
| 10700 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10701 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 10702 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10704 | |
| 10705 | TestCompletionCallback callback; |
| 10706 | |
| 10707 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10709 | |
| 10710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10712 | |
| 10713 | url::SchemeHostPort test_server(request.url); |
| 10714 | HttpServerProperties* http_server_properties = |
| 10715 | session->http_server_properties(); |
| 10716 | EXPECT_TRUE( |
| 10717 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10718 | |
| 10719 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10720 | |
| 10721 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10722 | ASSERT_TRUE(response); |
| 10723 | ASSERT_TRUE(response->headers); |
| 10724 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10725 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10726 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10727 | |
| 10728 | std::string response_data; |
| 10729 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10730 | EXPECT_EQ("hello world", response_data); |
| 10731 | |
| 10732 | EXPECT_TRUE( |
| 10733 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10734 | } |
| 10735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10736 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10737 | MockRead data_reads[] = { |
| 10738 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10739 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10740 | MockRead("\r\n"), |
| 10741 | MockRead("hello world"), |
| 10742 | MockRead(SYNCHRONOUS, OK), |
| 10743 | }; |
| 10744 | |
| 10745 | HttpRequestInfo request; |
| 10746 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10747 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10748 | |
| 10749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10751 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10752 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10753 | ssl.ssl_info.cert = |
| 10754 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10755 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10756 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10757 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10758 | TestCompletionCallback callback; |
| 10759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10761 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10762 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10763 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10765 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10766 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10767 | HttpServerProperties* http_server_properties = |
| 10768 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10769 | EXPECT_TRUE( |
| 10770 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10771 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10772 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10774 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10775 | ASSERT_TRUE(response); |
| 10776 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10777 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10778 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10779 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10780 | |
| 10781 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10782 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10783 | EXPECT_EQ("hello world", response_data); |
| 10784 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10785 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10786 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10787 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10788 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10789 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10790 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10791 | } |
| 10792 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10793 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10794 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10795 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10796 | MockRead data_reads[] = { |
| 10797 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10798 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10799 | MockRead("\r\n"), |
| 10800 | MockRead("hello world"), |
| 10801 | MockRead(SYNCHRONOUS, OK), |
| 10802 | }; |
| 10803 | |
| 10804 | HttpRequestInfo request; |
| 10805 | request.method = "GET"; |
| 10806 | request.url = GURL("http://www.example.org/"); |
| 10807 | request.load_flags = 0; |
| 10808 | |
| 10809 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10811 | |
| 10812 | TestCompletionCallback callback; |
| 10813 | |
| 10814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10816 | |
| 10817 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10818 | HttpServerProperties* http_server_properties = |
| 10819 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10820 | EXPECT_TRUE( |
| 10821 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10822 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10823 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10825 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10828 | ASSERT_TRUE(response); |
| 10829 | ASSERT_TRUE(response->headers); |
| 10830 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10831 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10832 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10833 | |
| 10834 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10835 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10836 | EXPECT_EQ("hello world", response_data); |
| 10837 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10838 | EXPECT_TRUE( |
| 10839 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10840 | } |
| 10841 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10842 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10843 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10844 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10845 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10846 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10847 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10848 | HttpRequestInfo request; |
| 10849 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10850 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10851 | request.load_flags = 0; |
| 10852 | |
| 10853 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10854 | StaticSocketDataProvider first_data; |
| 10855 | first_data.set_connect_data(mock_connect); |
| 10856 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10857 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10858 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10860 | |
| 10861 | MockRead data_reads[] = { |
| 10862 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10863 | MockRead(ASYNC, OK), |
| 10864 | }; |
| 10865 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10866 | 0); |
| 10867 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10868 | |
| 10869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10870 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10871 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10872 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10873 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10874 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10875 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10876 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10877 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10879 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10880 | TestCompletionCallback callback; |
| 10881 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10882 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10883 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10884 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10885 | } |
| 10886 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10887 | // Regression test for https://crbug.com/615497: |
| 10888 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10889 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10890 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10891 | HttpRequestInfo request; |
| 10892 | request.method = "GET"; |
| 10893 | request.url = GURL("http://www.example.org/"); |
| 10894 | request.load_flags = 0; |
| 10895 | |
| 10896 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10897 | StaticSocketDataProvider first_data; |
| 10898 | first_data.set_connect_data(mock_connect); |
| 10899 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10900 | |
| 10901 | MockRead data_reads[] = { |
| 10902 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10903 | MockRead(ASYNC, OK), |
| 10904 | }; |
| 10905 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10906 | 0); |
| 10907 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10908 | |
| 10909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10910 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10911 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10912 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10913 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10914 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10915 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10916 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10919 | TestCompletionCallback callback; |
| 10920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10921 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10922 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10923 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10924 | } |
| 10925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10926 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10927 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10929 | HttpServerProperties* http_server_properties = |
| 10930 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10931 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10932 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10933 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10934 | http_server_properties->SetQuicAlternativeService( |
| 10935 | test_server, alternative_service, expiration, |
| 10936 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10937 | EXPECT_EQ( |
| 10938 | 1u, |
| 10939 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10940 | |
| 10941 | // Send a clear header. |
| 10942 | MockRead data_reads[] = { |
| 10943 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10944 | MockRead("Alt-Svc: clear\r\n"), |
| 10945 | MockRead("\r\n"), |
| 10946 | MockRead("hello world"), |
| 10947 | MockRead(SYNCHRONOUS, OK), |
| 10948 | }; |
| 10949 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10951 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10952 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 10953 | ssl.ssl_info.cert = |
| 10954 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10955 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10957 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10958 | HttpRequestInfo request; |
| 10959 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10960 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10961 | |
| 10962 | TestCompletionCallback callback; |
| 10963 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10964 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10965 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10966 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10967 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10969 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10970 | ASSERT_TRUE(response); |
| 10971 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10972 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10973 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10974 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10975 | |
| 10976 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10977 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10978 | EXPECT_EQ("hello world", response_data); |
| 10979 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10980 | EXPECT_TRUE( |
| 10981 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10982 | } |
| 10983 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10984 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10985 | MockRead data_reads[] = { |
| 10986 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10987 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10988 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10989 | MockRead("hello world"), |
| 10990 | MockRead(SYNCHRONOUS, OK), |
| 10991 | }; |
| 10992 | |
| 10993 | HttpRequestInfo request; |
| 10994 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10995 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10996 | |
| 10997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10999 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11000 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11001 | ssl.ssl_info.cert = |
| 11002 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11003 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11004 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11005 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11006 | TestCompletionCallback callback; |
| 11007 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11009 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11010 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11011 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11013 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11014 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11015 | HttpServerProperties* http_server_properties = |
| 11016 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11017 | EXPECT_TRUE( |
| 11018 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11019 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11020 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11022 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11023 | ASSERT_TRUE(response); |
| 11024 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11025 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11026 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11027 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11028 | |
| 11029 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11030 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11031 | EXPECT_EQ("hello world", response_data); |
| 11032 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11033 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11034 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11035 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11036 | |
| 11037 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11038 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11039 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11040 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11041 | 1234); |
| 11042 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11043 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11044 | } |
| 11045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11046 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11047 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11048 | HostPortPair alternative("alternative.example.org", 443); |
| 11049 | std::string origin_url = "https://origin.example.org:443"; |
| 11050 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11051 | |
| 11052 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11053 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11054 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11056 | |
| 11057 | // HTTP/1.1 data for request. |
| 11058 | MockWrite http_writes[] = { |
| 11059 | MockWrite("GET / HTTP/1.1\r\n" |
| 11060 | "Host: alternative.example.org\r\n" |
| 11061 | "Connection: keep-alive\r\n\r\n"), |
| 11062 | }; |
| 11063 | |
| 11064 | MockRead http_reads[] = { |
| 11065 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11066 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11067 | "Content-Length: 40\r\n\r\n" |
| 11068 | "first HTTP/1.1 response from alternative"), |
| 11069 | }; |
| 11070 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11071 | http_writes, arraysize(http_writes)); |
| 11072 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11073 | |
| 11074 | StaticSocketDataProvider data_refused; |
| 11075 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11076 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11077 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11078 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11080 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11081 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11082 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11083 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11084 | http_server_properties->SetQuicAlternativeService( |
| 11085 | server, alternative_service, expiration, |
| 11086 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11087 | // Mark the QUIC alternative service as broken. |
| 11088 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11089 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11090 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11092 | request.method = "GET"; |
| 11093 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11094 | TestCompletionCallback callback; |
| 11095 | NetErrorDetails details; |
| 11096 | EXPECT_FALSE(details.quic_broken); |
| 11097 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11098 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11099 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11100 | EXPECT_TRUE(details.quic_broken); |
| 11101 | } |
| 11102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11103 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11104 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11105 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11106 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11107 | std::string origin_url = "https://origin.example.org:443"; |
| 11108 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11109 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11110 | |
| 11111 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11112 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11113 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11115 | |
| 11116 | // HTTP/1.1 data for request. |
| 11117 | MockWrite http_writes[] = { |
| 11118 | MockWrite("GET / HTTP/1.1\r\n" |
| 11119 | "Host: alternative1.example.org\r\n" |
| 11120 | "Connection: keep-alive\r\n\r\n"), |
| 11121 | }; |
| 11122 | |
| 11123 | MockRead http_reads[] = { |
| 11124 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11125 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11126 | "Content-Length: 40\r\n\r\n" |
| 11127 | "first HTTP/1.1 response from alternative1"), |
| 11128 | }; |
| 11129 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 11130 | http_writes, arraysize(http_writes)); |
| 11131 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11132 | |
| 11133 | StaticSocketDataProvider data_refused; |
| 11134 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11135 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11136 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11138 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11139 | session->http_server_properties(); |
| 11140 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11141 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11142 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11143 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11144 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11145 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11146 | alternative_service_info_vector.push_back( |
| 11147 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11148 | alternative_service1, expiration, |
| 11149 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11150 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11151 | alternative_service_info_vector.push_back( |
| 11152 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11153 | alternative_service2, expiration, |
| 11154 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11155 | |
| 11156 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11157 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11158 | |
| 11159 | // Mark one of the QUIC alternative service as broken. |
| 11160 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11161 | EXPECT_EQ(2u, |
| 11162 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11163 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11164 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11165 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11166 | request.method = "GET"; |
| 11167 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11168 | TestCompletionCallback callback; |
| 11169 | NetErrorDetails details; |
| 11170 | EXPECT_FALSE(details.quic_broken); |
| 11171 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11172 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11173 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11174 | EXPECT_FALSE(details.quic_broken); |
| 11175 | } |
| 11176 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11177 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11178 | HttpRequestInfo request; |
| 11179 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11180 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11181 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11182 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11183 | StaticSocketDataProvider first_data; |
| 11184 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11185 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11186 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11187 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11189 | |
| 11190 | MockRead data_reads[] = { |
| 11191 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11192 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11193 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11194 | }; |
| 11195 | StaticSocketDataProvider second_data( |
| 11196 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11197 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11198 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11199 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11200 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11201 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11202 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11203 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11204 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11205 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11206 | // Port is ignored by MockConnect anyway. |
| 11207 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11208 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11209 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11210 | http_server_properties->SetHttp2AlternativeService( |
| 11211 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11213 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11214 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11215 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11216 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11218 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11221 | ASSERT_TRUE(response); |
| 11222 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11223 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11224 | |
| 11225 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11226 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11227 | EXPECT_EQ("hello world", response_data); |
| 11228 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11229 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11230 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11231 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11232 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11233 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11234 | EXPECT_TRUE( |
| 11235 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11236 | } |
| 11237 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11238 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11239 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11240 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11241 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11242 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11243 | HttpRequestInfo restricted_port_request; |
| 11244 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11245 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11246 | restricted_port_request.load_flags = 0; |
| 11247 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11248 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11249 | StaticSocketDataProvider first_data; |
| 11250 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11251 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11252 | |
| 11253 | MockRead data_reads[] = { |
| 11254 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11255 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11256 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11257 | }; |
| 11258 | StaticSocketDataProvider second_data( |
| 11259 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11260 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11261 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11262 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11264 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11265 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11266 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11267 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11268 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11269 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11270 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11271 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11272 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11273 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11274 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11275 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11278 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11280 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11281 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11283 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11284 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11285 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11286 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11287 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11288 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11289 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11290 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11291 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11292 | |
| 11293 | HttpRequestInfo restricted_port_request; |
| 11294 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11295 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11296 | restricted_port_request.load_flags = 0; |
| 11297 | |
| 11298 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11299 | StaticSocketDataProvider first_data; |
| 11300 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11301 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11302 | |
| 11303 | MockRead data_reads[] = { |
| 11304 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11305 | MockRead("hello world"), |
| 11306 | MockRead(ASYNC, OK), |
| 11307 | }; |
| 11308 | StaticSocketDataProvider second_data( |
| 11309 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11310 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11311 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11312 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11313 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11314 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11315 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11316 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11317 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11318 | session->http_server_properties(); |
| 11319 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11320 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11321 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11322 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11323 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11324 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11325 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11326 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11327 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11328 | TestCompletionCallback callback; |
| 11329 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11330 | EXPECT_EQ(ERR_IO_PENDING, |
| 11331 | trans.Start(&restricted_port_request, callback.callback(), |
| 11332 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11333 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11334 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11335 | } |
| 11336 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11337 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11338 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11339 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11340 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11341 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11342 | HttpRequestInfo restricted_port_request; |
| 11343 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11344 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11345 | restricted_port_request.load_flags = 0; |
| 11346 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11347 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11348 | StaticSocketDataProvider first_data; |
| 11349 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11350 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11351 | |
| 11352 | MockRead data_reads[] = { |
| 11353 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11354 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11355 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11356 | }; |
| 11357 | StaticSocketDataProvider second_data( |
| 11358 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11359 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11360 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11361 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11363 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11365 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11366 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11367 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11368 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11369 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11370 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11371 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11372 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11373 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11374 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11377 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11378 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11379 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11380 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11382 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11383 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11384 | } |
| 11385 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11386 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11387 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11388 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11389 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11390 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11391 | HttpRequestInfo unrestricted_port_request; |
| 11392 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11393 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11394 | unrestricted_port_request.load_flags = 0; |
| 11395 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11396 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11397 | StaticSocketDataProvider first_data; |
| 11398 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11399 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11400 | |
| 11401 | MockRead data_reads[] = { |
| 11402 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11403 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11404 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11405 | }; |
| 11406 | StaticSocketDataProvider second_data( |
| 11407 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11409 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11410 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11411 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11412 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11414 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11415 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11416 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11417 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11418 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11419 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11420 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11421 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11422 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11423 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11424 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11425 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11426 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11428 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11429 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11431 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11432 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11433 | } |
| 11434 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11435 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11436 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11437 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11438 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11439 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11440 | HttpRequestInfo unrestricted_port_request; |
| 11441 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11442 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11443 | unrestricted_port_request.load_flags = 0; |
| 11444 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11445 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11446 | StaticSocketDataProvider first_data; |
| 11447 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11448 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11449 | |
| 11450 | MockRead data_reads[] = { |
| 11451 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11452 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11453 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11454 | }; |
| 11455 | StaticSocketDataProvider second_data( |
| 11456 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11457 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11458 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11459 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11461 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11463 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11464 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11465 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11466 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11467 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11468 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11469 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11470 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11471 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11472 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11475 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11477 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11478 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11480 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11481 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11482 | } |
| 11483 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11484 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11485 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11486 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11487 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11488 | HttpRequestInfo request; |
| 11489 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11490 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11491 | |
| 11492 | // The alternate protocol request will error out before we attempt to connect, |
| 11493 | // so only the standard HTTP request will try to connect. |
| 11494 | MockRead data_reads[] = { |
| 11495 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11496 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11497 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11498 | }; |
| 11499 | StaticSocketDataProvider data( |
| 11500 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11501 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11504 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11505 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11506 | session->http_server_properties(); |
| 11507 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11508 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11509 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11510 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11511 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11512 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11514 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11515 | TestCompletionCallback callback; |
| 11516 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11517 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11519 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11520 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11522 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11523 | ASSERT_TRUE(response); |
| 11524 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11525 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11526 | |
| 11527 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11528 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11529 | EXPECT_EQ("hello world", response_data); |
| 11530 | } |
| 11531 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11532 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11533 | HttpRequestInfo request; |
| 11534 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11535 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11536 | |
| 11537 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11538 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11539 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11540 | MockRead("\r\n"), |
| 11541 | MockRead("hello world"), |
| 11542 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11543 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11544 | |
| 11545 | StaticSocketDataProvider first_transaction( |
| 11546 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11547 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11548 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11549 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11551 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11552 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11553 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11554 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11555 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11556 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11557 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11558 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11559 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11560 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11561 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11562 | }; |
| 11563 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11564 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11565 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11566 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11567 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11568 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11569 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11570 | NULL, 0, NULL, 0); |
| 11571 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11572 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11573 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11574 | &hanging_non_alternate_protocol_socket); |
| 11575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11576 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11579 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11580 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11582 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11584 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11585 | |
| 11586 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11587 | ASSERT_TRUE(response); |
| 11588 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11589 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11590 | |
| 11591 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11592 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11593 | EXPECT_EQ("hello world", response_data); |
| 11594 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11595 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11596 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11598 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11600 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11601 | |
| 11602 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11603 | ASSERT_TRUE(response); |
| 11604 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11605 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11606 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11607 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11608 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11609 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11610 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11611 | } |
| 11612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11613 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11614 | HttpRequestInfo request; |
| 11615 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11616 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11617 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11618 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11619 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11620 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11621 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11622 | MockRead("\r\n"), |
| 11623 | MockRead("hello world"), |
| 11624 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11625 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11626 | }; |
| 11627 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11628 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11629 | 0); |
| 11630 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11631 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11632 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11633 | ssl_http11.ssl_info.cert = |
| 11634 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11635 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11636 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11637 | |
| 11638 | // Second transaction starts an alternative and a non-alternative Job. |
| 11639 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11640 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11641 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11642 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11643 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11644 | |
| 11645 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11646 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11647 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11648 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11649 | // Third transaction starts an alternative and a non-alternative job. |
| 11650 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11651 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11652 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11653 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11654 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11655 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11656 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11657 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11658 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11659 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11660 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11661 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11662 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11663 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11664 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11665 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11666 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11667 | }; |
| 11668 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11669 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11670 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11671 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11672 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11673 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11674 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11675 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11676 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11677 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11680 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11681 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11682 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11683 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11685 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11686 | |
| 11687 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11688 | ASSERT_TRUE(response); |
| 11689 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11690 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11691 | |
| 11692 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11693 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11694 | EXPECT_EQ("hello world", response_data); |
| 11695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11696 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11697 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11698 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11701 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11702 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11703 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11705 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11706 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11707 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11708 | |
| 11709 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11710 | ASSERT_TRUE(response); |
| 11711 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11712 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11713 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11714 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11715 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11716 | EXPECT_EQ("hello!", response_data); |
| 11717 | |
| 11718 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11719 | ASSERT_TRUE(response); |
| 11720 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11721 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11722 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11723 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11724 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11725 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11726 | } |
| 11727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11728 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11729 | HttpRequestInfo request; |
| 11730 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11731 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11732 | |
| 11733 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11734 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11735 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11736 | MockRead("\r\n"), |
| 11737 | MockRead("hello world"), |
| 11738 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11739 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11740 | }; |
| 11741 | |
| 11742 | StaticSocketDataProvider first_transaction( |
| 11743 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11744 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11745 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11746 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11747 | ssl.ssl_info.cert = |
| 11748 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11749 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11751 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11752 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11753 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11754 | NULL, 0, NULL, 0); |
| 11755 | hanging_alternate_protocol_socket.set_connect_data( |
| 11756 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11757 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11758 | &hanging_alternate_protocol_socket); |
| 11759 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11760 | // 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] | 11761 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11762 | NULL, 0); |
| 11763 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11766 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11769 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11770 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11771 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11772 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11774 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11775 | |
| 11776 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11777 | ASSERT_TRUE(response); |
| 11778 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11779 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11780 | |
| 11781 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11782 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11783 | EXPECT_EQ("hello world", response_data); |
| 11784 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11785 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11786 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11787 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11788 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11790 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11791 | |
| 11792 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11793 | ASSERT_TRUE(response); |
| 11794 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11795 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11796 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11797 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11798 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11799 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11800 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11801 | } |
| 11802 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11803 | class CapturingProxyResolver : public ProxyResolver { |
| 11804 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11805 | CapturingProxyResolver() = default; |
| 11806 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11807 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11808 | int GetProxyForURL(const GURL& url, |
| 11809 | ProxyInfo* results, |
| 11810 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11811 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11812 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11813 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11814 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11815 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11816 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11817 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11818 | } |
| 11819 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11820 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11821 | |
| 11822 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11823 | std::vector<GURL> resolved_; |
| 11824 | |
| 11825 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11826 | }; |
| 11827 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11828 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11829 | public: |
| 11830 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11831 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11832 | |
| 11833 | int CreateProxyResolver( |
| 11834 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11835 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11836 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11837 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11838 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11839 | return OK; |
| 11840 | } |
| 11841 | |
| 11842 | private: |
| 11843 | ProxyResolver* resolver_; |
| 11844 | }; |
| 11845 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11846 | // Test that proxy is resolved using the origin url, |
| 11847 | // regardless of the alternative server. |
| 11848 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11849 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11850 | ProxyConfig proxy_config; |
| 11851 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11852 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11853 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11854 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11855 | |
| 11856 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11857 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11858 | &capturing_proxy_resolver); |
| 11859 | |
| 11860 | TestNetLog net_log; |
| 11861 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11862 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11863 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11864 | &net_log); |
| 11865 | |
| 11866 | session_deps_.net_log = &net_log; |
| 11867 | |
| 11868 | // Configure alternative service with a hostname that is not bypassed by the |
| 11869 | // proxy. |
| 11870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11871 | HttpServerProperties* http_server_properties = |
| 11872 | session->http_server_properties(); |
| 11873 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11874 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11875 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11876 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11877 | http_server_properties->SetHttp2AlternativeService( |
| 11878 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11879 | |
| 11880 | // Non-alternative job should hang. |
| 11881 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11882 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11883 | nullptr, 0); |
| 11884 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11885 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11886 | &hanging_alternate_protocol_socket); |
| 11887 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11888 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11889 | |
| 11890 | HttpRequestInfo request; |
| 11891 | request.method = "GET"; |
| 11892 | request.url = GURL("https://www.example.org/"); |
| 11893 | request.load_flags = 0; |
| 11894 | |
| 11895 | SpdySerializedFrame req( |
| 11896 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11897 | |
| 11898 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11899 | |
| 11900 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11901 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11902 | MockRead spdy_reads[] = { |
| 11903 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11904 | }; |
| 11905 | |
| 11906 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11907 | arraysize(spdy_writes)); |
| 11908 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11909 | |
| 11910 | TestCompletionCallback callback; |
| 11911 | |
| 11912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11913 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11915 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11916 | |
| 11917 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11918 | ASSERT_TRUE(response); |
| 11919 | ASSERT_TRUE(response->headers); |
| 11920 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11921 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11922 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11923 | |
| 11924 | std::string response_data; |
| 11925 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11926 | EXPECT_EQ("hello!", response_data); |
| 11927 | |
| 11928 | // Origin host bypasses proxy, no resolution should have happened. |
| 11929 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11930 | } |
| 11931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11932 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11933 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11934 | proxy_config.set_auto_detect(true); |
| 11935 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11936 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11937 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11938 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11939 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11940 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11941 | &capturing_proxy_resolver), |
| 11942 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11943 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11944 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11945 | |
| 11946 | HttpRequestInfo request; |
| 11947 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11948 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11949 | |
| 11950 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11951 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11952 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11953 | MockRead("\r\n"), |
| 11954 | MockRead("hello world"), |
| 11955 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11956 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11957 | }; |
| 11958 | |
| 11959 | StaticSocketDataProvider first_transaction( |
| 11960 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11961 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11962 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11963 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11964 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11965 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11966 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11967 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11968 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11969 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11970 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11971 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11972 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11973 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11974 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11975 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11976 | }; |
| 11977 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11978 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11979 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11980 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11981 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11982 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11983 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11984 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11985 | }; |
| 11986 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11987 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11988 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11989 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11990 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11991 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11992 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11993 | NULL, 0, NULL, 0); |
| 11994 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11995 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11996 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11997 | &hanging_non_alternate_protocol_socket); |
| 11998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11999 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12002 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12003 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12005 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12007 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12008 | |
| 12009 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12010 | ASSERT_TRUE(response); |
| 12011 | ASSERT_TRUE(response->headers); |
| 12012 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12013 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12014 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12015 | |
| 12016 | std::string response_data; |
| 12017 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12018 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12019 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12020 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12021 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12022 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12023 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12025 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12026 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12027 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12028 | ASSERT_TRUE(response); |
| 12029 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12030 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12031 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12032 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12033 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12034 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12035 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12036 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12037 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12038 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12039 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12040 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12041 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12042 | LoadTimingInfo load_timing_info; |
| 12043 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12044 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12045 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12046 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12047 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12048 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12049 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12050 | HttpRequestInfo request; |
| 12051 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12052 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12053 | |
| 12054 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12055 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12056 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12057 | MockRead("\r\n"), |
| 12058 | MockRead("hello world"), |
| 12059 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12060 | }; |
| 12061 | |
| 12062 | StaticSocketDataProvider first_transaction( |
| 12063 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12064 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12065 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12066 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12068 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12069 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12070 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12071 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12072 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12073 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12074 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 12075 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12076 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12077 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12078 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12079 | }; |
| 12080 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12081 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12082 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12083 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12084 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12085 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12088 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12089 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12090 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12092 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12094 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12095 | |
| 12096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12097 | ASSERT_TRUE(response); |
| 12098 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12099 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12100 | |
| 12101 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12102 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12103 | EXPECT_EQ("hello world", response_data); |
| 12104 | |
| 12105 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12106 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12107 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 12108 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12109 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12110 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12111 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12112 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12113 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12114 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12115 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12117 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12118 | |
| 12119 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12120 | ASSERT_TRUE(response); |
| 12121 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12122 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12123 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12124 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12125 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12126 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12127 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12128 | } |
| 12129 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12130 | // GenerateAuthToken is a mighty big test. |
| 12131 | // It tests all permutation of GenerateAuthToken behavior: |
| 12132 | // - Synchronous and Asynchronous completion. |
| 12133 | // - OK or error on completion. |
| 12134 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12135 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12136 | // - Non-authenticating and authenticating backend. |
| 12137 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12138 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12139 | // problems generating an auth token for an authenticating proxy, we don't |
| 12140 | // need to test all permutations of the backend server). |
| 12141 | // |
| 12142 | // The test proceeds by going over each of the configuration cases, and |
| 12143 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12144 | // specifies both the configuration for the test as well as the expectations |
| 12145 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12146 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12147 | static const char kServer[] = "http://www.example.com"; |
| 12148 | static const char kSecureServer[] = "https://www.example.com"; |
| 12149 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12150 | |
| 12151 | enum AuthTiming { |
| 12152 | AUTH_NONE, |
| 12153 | AUTH_SYNC, |
| 12154 | AUTH_ASYNC, |
| 12155 | }; |
| 12156 | |
| 12157 | const MockWrite kGet( |
| 12158 | "GET / HTTP/1.1\r\n" |
| 12159 | "Host: www.example.com\r\n" |
| 12160 | "Connection: keep-alive\r\n\r\n"); |
| 12161 | const MockWrite kGetProxy( |
| 12162 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12163 | "Host: www.example.com\r\n" |
| 12164 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12165 | const MockWrite kGetAuth( |
| 12166 | "GET / HTTP/1.1\r\n" |
| 12167 | "Host: www.example.com\r\n" |
| 12168 | "Connection: keep-alive\r\n" |
| 12169 | "Authorization: auth_token\r\n\r\n"); |
| 12170 | const MockWrite kGetProxyAuth( |
| 12171 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12172 | "Host: www.example.com\r\n" |
| 12173 | "Proxy-Connection: keep-alive\r\n" |
| 12174 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12175 | const MockWrite kGetAuthThroughProxy( |
| 12176 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12177 | "Host: www.example.com\r\n" |
| 12178 | "Proxy-Connection: keep-alive\r\n" |
| 12179 | "Authorization: auth_token\r\n\r\n"); |
| 12180 | const MockWrite kGetAuthWithProxyAuth( |
| 12181 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12182 | "Host: www.example.com\r\n" |
| 12183 | "Proxy-Connection: keep-alive\r\n" |
| 12184 | "Proxy-Authorization: auth_token\r\n" |
| 12185 | "Authorization: auth_token\r\n\r\n"); |
| 12186 | const MockWrite kConnect( |
| 12187 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12188 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12189 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12190 | const MockWrite kConnectProxyAuth( |
| 12191 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12192 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12193 | "Proxy-Connection: keep-alive\r\n" |
| 12194 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12195 | |
| 12196 | const MockRead kSuccess( |
| 12197 | "HTTP/1.1 200 OK\r\n" |
| 12198 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12199 | "Content-Length: 3\r\n\r\n" |
| 12200 | "Yes"); |
| 12201 | const MockRead kFailure( |
| 12202 | "Should not be called."); |
| 12203 | const MockRead kServerChallenge( |
| 12204 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12205 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12206 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12207 | "Content-Length: 14\r\n\r\n" |
| 12208 | "Unauthorized\r\n"); |
| 12209 | const MockRead kProxyChallenge( |
| 12210 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12211 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12212 | "Proxy-Connection: close\r\n" |
| 12213 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12214 | "Content-Length: 14\r\n\r\n" |
| 12215 | "Unauthorized\r\n"); |
| 12216 | const MockRead kProxyConnected( |
| 12217 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12218 | |
| 12219 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12220 | // no constructors, but the C++ compiler on Windows warns about |
| 12221 | // unspecified data in compound literals. So, moved to using constructors, |
| 12222 | // and TestRound's created with the default constructor should not be used. |
| 12223 | struct TestRound { |
| 12224 | TestRound() |
| 12225 | : expected_rv(ERR_UNEXPECTED), |
| 12226 | extra_write(NULL), |
| 12227 | extra_read(NULL) { |
| 12228 | } |
| 12229 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12230 | int expected_rv_arg) |
| 12231 | : write(write_arg), |
| 12232 | read(read_arg), |
| 12233 | expected_rv(expected_rv_arg), |
| 12234 | extra_write(NULL), |
| 12235 | extra_read(NULL) { |
| 12236 | } |
| 12237 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12238 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12239 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12240 | : write(write_arg), |
| 12241 | read(read_arg), |
| 12242 | expected_rv(expected_rv_arg), |
| 12243 | extra_write(extra_write_arg), |
| 12244 | extra_read(extra_read_arg) { |
| 12245 | } |
| 12246 | MockWrite write; |
| 12247 | MockRead read; |
| 12248 | int expected_rv; |
| 12249 | const MockWrite* extra_write; |
| 12250 | const MockRead* extra_read; |
| 12251 | }; |
| 12252 | |
| 12253 | static const int kNoSSL = 500; |
| 12254 | |
| 12255 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12256 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12257 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12258 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12259 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12260 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12261 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12262 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12263 | int num_auth_rounds; |
| 12264 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12265 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12266 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12267 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12268 | {__LINE__, |
| 12269 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12270 | AUTH_NONE, |
| 12271 | OK, |
| 12272 | kServer, |
| 12273 | AUTH_NONE, |
| 12274 | OK, |
| 12275 | 1, |
| 12276 | kNoSSL, |
| 12277 | {TestRound(kGet, kSuccess, OK)}}, |
| 12278 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12279 | {__LINE__, |
| 12280 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12281 | AUTH_NONE, |
| 12282 | OK, |
| 12283 | kServer, |
| 12284 | AUTH_SYNC, |
| 12285 | OK, |
| 12286 | 2, |
| 12287 | kNoSSL, |
| 12288 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12289 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12290 | {__LINE__, |
| 12291 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12292 | AUTH_NONE, |
| 12293 | OK, |
| 12294 | kServer, |
| 12295 | AUTH_SYNC, |
| 12296 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12297 | 3, |
| 12298 | kNoSSL, |
| 12299 | {TestRound(kGet, kServerChallenge, OK), |
| 12300 | TestRound(kGet, kServerChallenge, OK), |
| 12301 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12302 | {__LINE__, |
| 12303 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12304 | AUTH_NONE, |
| 12305 | OK, |
| 12306 | kServer, |
| 12307 | AUTH_SYNC, |
| 12308 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12309 | 2, |
| 12310 | kNoSSL, |
| 12311 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12312 | {__LINE__, |
| 12313 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12314 | AUTH_NONE, |
| 12315 | OK, |
| 12316 | kServer, |
| 12317 | AUTH_SYNC, |
| 12318 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12319 | 2, |
| 12320 | kNoSSL, |
| 12321 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12322 | {__LINE__, |
| 12323 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12324 | AUTH_SYNC, |
| 12325 | ERR_FAILED, |
| 12326 | kServer, |
| 12327 | AUTH_NONE, |
| 12328 | OK, |
| 12329 | 2, |
| 12330 | kNoSSL, |
| 12331 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12332 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12333 | {__LINE__, |
| 12334 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12335 | AUTH_ASYNC, |
| 12336 | ERR_FAILED, |
| 12337 | kServer, |
| 12338 | AUTH_NONE, |
| 12339 | OK, |
| 12340 | 2, |
| 12341 | kNoSSL, |
| 12342 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12343 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12344 | {__LINE__, |
| 12345 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12346 | AUTH_NONE, |
| 12347 | OK, |
| 12348 | kServer, |
| 12349 | AUTH_SYNC, |
| 12350 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12351 | 2, |
| 12352 | kNoSSL, |
| 12353 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12354 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12355 | {__LINE__, |
| 12356 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12357 | AUTH_NONE, |
| 12358 | OK, |
| 12359 | kServer, |
| 12360 | AUTH_ASYNC, |
| 12361 | ERR_FAILED, |
| 12362 | 2, |
| 12363 | kNoSSL, |
| 12364 | {TestRound(kGet, kServerChallenge, OK), |
| 12365 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12366 | {__LINE__, |
| 12367 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12368 | AUTH_NONE, |
| 12369 | OK, |
| 12370 | kServer, |
| 12371 | AUTH_ASYNC, |
| 12372 | OK, |
| 12373 | 2, |
| 12374 | kNoSSL, |
| 12375 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12376 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12377 | {__LINE__, |
| 12378 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12379 | AUTH_NONE, |
| 12380 | OK, |
| 12381 | kServer, |
| 12382 | AUTH_ASYNC, |
| 12383 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12384 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12385 | kNoSSL, |
| 12386 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12387 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12388 | TestRound(kGet, kServerChallenge, OK), |
| 12389 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12390 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12391 | {__LINE__, |
| 12392 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12393 | AUTH_NONE, |
| 12394 | OK, |
| 12395 | kServer, |
| 12396 | AUTH_NONE, |
| 12397 | OK, |
| 12398 | 1, |
| 12399 | kNoSSL, |
| 12400 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12401 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12402 | {__LINE__, |
| 12403 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12404 | AUTH_NONE, |
| 12405 | OK, |
| 12406 | kServer, |
| 12407 | AUTH_SYNC, |
| 12408 | OK, |
| 12409 | 2, |
| 12410 | kNoSSL, |
| 12411 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12412 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12413 | {__LINE__, |
| 12414 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12415 | AUTH_NONE, |
| 12416 | OK, |
| 12417 | kServer, |
| 12418 | AUTH_SYNC, |
| 12419 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12420 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12421 | kNoSSL, |
| 12422 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12423 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12424 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12425 | {__LINE__, |
| 12426 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12427 | AUTH_NONE, |
| 12428 | OK, |
| 12429 | kServer, |
| 12430 | AUTH_ASYNC, |
| 12431 | OK, |
| 12432 | 2, |
| 12433 | kNoSSL, |
| 12434 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12435 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12436 | {__LINE__, |
| 12437 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12438 | AUTH_NONE, |
| 12439 | OK, |
| 12440 | kServer, |
| 12441 | AUTH_ASYNC, |
| 12442 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12443 | 2, |
| 12444 | kNoSSL, |
| 12445 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12446 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12447 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12448 | {__LINE__, |
| 12449 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12450 | AUTH_SYNC, |
| 12451 | OK, |
| 12452 | kServer, |
| 12453 | AUTH_NONE, |
| 12454 | OK, |
| 12455 | 2, |
| 12456 | kNoSSL, |
| 12457 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12458 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12459 | {__LINE__, |
| 12460 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12461 | AUTH_SYNC, |
| 12462 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12463 | kServer, |
| 12464 | AUTH_NONE, |
| 12465 | OK, |
| 12466 | 2, |
| 12467 | kNoSSL, |
| 12468 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12469 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12470 | {__LINE__, |
| 12471 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12472 | AUTH_ASYNC, |
| 12473 | OK, |
| 12474 | kServer, |
| 12475 | AUTH_NONE, |
| 12476 | OK, |
| 12477 | 2, |
| 12478 | kNoSSL, |
| 12479 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12480 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12481 | {__LINE__, |
| 12482 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12483 | AUTH_ASYNC, |
| 12484 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12485 | kServer, |
| 12486 | AUTH_NONE, |
| 12487 | OK, |
| 12488 | 2, |
| 12489 | kNoSSL, |
| 12490 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12491 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12492 | {__LINE__, |
| 12493 | kProxy, |
| 12494 | AUTH_ASYNC, |
| 12495 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12496 | kServer, |
| 12497 | AUTH_NONE, |
| 12498 | OK, |
| 12499 | 3, |
| 12500 | kNoSSL, |
| 12501 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12502 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12503 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12504 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12505 | {__LINE__, |
| 12506 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12507 | AUTH_SYNC, |
| 12508 | OK, |
| 12509 | kServer, |
| 12510 | AUTH_SYNC, |
| 12511 | OK, |
| 12512 | 3, |
| 12513 | kNoSSL, |
| 12514 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12515 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12516 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12517 | {__LINE__, |
| 12518 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12519 | AUTH_SYNC, |
| 12520 | OK, |
| 12521 | kServer, |
| 12522 | AUTH_SYNC, |
| 12523 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12524 | 3, |
| 12525 | kNoSSL, |
| 12526 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12527 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12528 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12529 | {__LINE__, |
| 12530 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12531 | AUTH_ASYNC, |
| 12532 | OK, |
| 12533 | kServer, |
| 12534 | AUTH_SYNC, |
| 12535 | OK, |
| 12536 | 3, |
| 12537 | kNoSSL, |
| 12538 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12539 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12540 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12541 | {__LINE__, |
| 12542 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12543 | AUTH_ASYNC, |
| 12544 | OK, |
| 12545 | kServer, |
| 12546 | AUTH_SYNC, |
| 12547 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12548 | 3, |
| 12549 | kNoSSL, |
| 12550 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12551 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12552 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12553 | {__LINE__, |
| 12554 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12555 | AUTH_SYNC, |
| 12556 | OK, |
| 12557 | kServer, |
| 12558 | AUTH_ASYNC, |
| 12559 | OK, |
| 12560 | 3, |
| 12561 | kNoSSL, |
| 12562 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12563 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12564 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12565 | {__LINE__, |
| 12566 | kProxy, |
| 12567 | AUTH_SYNC, |
| 12568 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12569 | kServer, |
| 12570 | AUTH_ASYNC, |
| 12571 | OK, |
| 12572 | 4, |
| 12573 | kNoSSL, |
| 12574 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12575 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12576 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12577 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12578 | {__LINE__, |
| 12579 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12580 | AUTH_SYNC, |
| 12581 | OK, |
| 12582 | kServer, |
| 12583 | AUTH_ASYNC, |
| 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_ASYNC, |
| 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, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12604 | AUTH_ASYNC, |
| 12605 | OK, |
| 12606 | kServer, |
| 12607 | AUTH_ASYNC, |
| 12608 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12609 | 3, |
| 12610 | kNoSSL, |
| 12611 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12612 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12613 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12614 | {__LINE__, |
| 12615 | kProxy, |
| 12616 | AUTH_ASYNC, |
| 12617 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12618 | kServer, |
| 12619 | AUTH_ASYNC, |
| 12620 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12621 | 4, |
| 12622 | kNoSSL, |
| 12623 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12624 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12625 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12626 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12627 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12628 | {__LINE__, |
| 12629 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12630 | AUTH_NONE, |
| 12631 | OK, |
| 12632 | kSecureServer, |
| 12633 | AUTH_NONE, |
| 12634 | OK, |
| 12635 | 1, |
| 12636 | 0, |
| 12637 | {TestRound(kGet, kSuccess, OK)}}, |
| 12638 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12639 | {__LINE__, |
| 12640 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12641 | AUTH_NONE, |
| 12642 | OK, |
| 12643 | kSecureServer, |
| 12644 | AUTH_SYNC, |
| 12645 | OK, |
| 12646 | 2, |
| 12647 | 0, |
| 12648 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12649 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12650 | {__LINE__, |
| 12651 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12652 | AUTH_NONE, |
| 12653 | OK, |
| 12654 | kSecureServer, |
| 12655 | AUTH_SYNC, |
| 12656 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12657 | 2, |
| 12658 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12659 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12660 | {__LINE__, |
| 12661 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12662 | AUTH_NONE, |
| 12663 | OK, |
| 12664 | kSecureServer, |
| 12665 | AUTH_ASYNC, |
| 12666 | OK, |
| 12667 | 2, |
| 12668 | 0, |
| 12669 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12670 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12671 | {__LINE__, |
| 12672 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12673 | AUTH_NONE, |
| 12674 | OK, |
| 12675 | kSecureServer, |
| 12676 | AUTH_ASYNC, |
| 12677 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12678 | 2, |
| 12679 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12680 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12681 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12682 | {__LINE__, |
| 12683 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12684 | AUTH_NONE, |
| 12685 | OK, |
| 12686 | kSecureServer, |
| 12687 | AUTH_NONE, |
| 12688 | OK, |
| 12689 | 1, |
| 12690 | 0, |
| 12691 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12692 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12693 | {__LINE__, |
| 12694 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12695 | AUTH_NONE, |
| 12696 | OK, |
| 12697 | kSecureServer, |
| 12698 | AUTH_SYNC, |
| 12699 | OK, |
| 12700 | 2, |
| 12701 | 0, |
| 12702 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12703 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12704 | {__LINE__, |
| 12705 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12706 | AUTH_NONE, |
| 12707 | OK, |
| 12708 | kSecureServer, |
| 12709 | AUTH_SYNC, |
| 12710 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12711 | 2, |
| 12712 | 0, |
| 12713 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12714 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12715 | {__LINE__, |
| 12716 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12717 | AUTH_NONE, |
| 12718 | OK, |
| 12719 | kSecureServer, |
| 12720 | AUTH_ASYNC, |
| 12721 | OK, |
| 12722 | 2, |
| 12723 | 0, |
| 12724 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12725 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12726 | {__LINE__, |
| 12727 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12728 | AUTH_NONE, |
| 12729 | OK, |
| 12730 | kSecureServer, |
| 12731 | AUTH_ASYNC, |
| 12732 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12733 | 2, |
| 12734 | 0, |
| 12735 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12736 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12737 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12738 | {__LINE__, |
| 12739 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12740 | AUTH_SYNC, |
| 12741 | OK, |
| 12742 | kSecureServer, |
| 12743 | AUTH_NONE, |
| 12744 | OK, |
| 12745 | 2, |
| 12746 | 1, |
| 12747 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12748 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12749 | {__LINE__, |
| 12750 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12751 | AUTH_SYNC, |
| 12752 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12753 | kSecureServer, |
| 12754 | AUTH_NONE, |
| 12755 | OK, |
| 12756 | 2, |
| 12757 | kNoSSL, |
| 12758 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12759 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12760 | {__LINE__, |
| 12761 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12762 | AUTH_SYNC, |
| 12763 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12764 | kSecureServer, |
| 12765 | AUTH_NONE, |
| 12766 | OK, |
| 12767 | 2, |
| 12768 | kNoSSL, |
| 12769 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12770 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12771 | {__LINE__, |
| 12772 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12773 | AUTH_SYNC, |
| 12774 | ERR_UNEXPECTED, |
| 12775 | kSecureServer, |
| 12776 | AUTH_NONE, |
| 12777 | OK, |
| 12778 | 2, |
| 12779 | kNoSSL, |
| 12780 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12781 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12782 | {__LINE__, |
| 12783 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12784 | AUTH_ASYNC, |
| 12785 | OK, |
| 12786 | kSecureServer, |
| 12787 | AUTH_NONE, |
| 12788 | OK, |
| 12789 | 2, |
| 12790 | 1, |
| 12791 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12792 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12793 | {__LINE__, |
| 12794 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12795 | AUTH_ASYNC, |
| 12796 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12797 | kSecureServer, |
| 12798 | AUTH_NONE, |
| 12799 | OK, |
| 12800 | 2, |
| 12801 | kNoSSL, |
| 12802 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12803 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12804 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12805 | {__LINE__, |
| 12806 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12807 | AUTH_SYNC, |
| 12808 | OK, |
| 12809 | kSecureServer, |
| 12810 | AUTH_SYNC, |
| 12811 | OK, |
| 12812 | 3, |
| 12813 | 1, |
| 12814 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12815 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12816 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12817 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12818 | {__LINE__, |
| 12819 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12820 | AUTH_SYNC, |
| 12821 | OK, |
| 12822 | kSecureServer, |
| 12823 | AUTH_SYNC, |
| 12824 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12825 | 3, |
| 12826 | 1, |
| 12827 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12828 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12829 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12830 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12831 | {__LINE__, |
| 12832 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12833 | AUTH_ASYNC, |
| 12834 | OK, |
| 12835 | kSecureServer, |
| 12836 | AUTH_SYNC, |
| 12837 | OK, |
| 12838 | 3, |
| 12839 | 1, |
| 12840 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12841 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12842 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12843 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12844 | {__LINE__, |
| 12845 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12846 | AUTH_ASYNC, |
| 12847 | OK, |
| 12848 | kSecureServer, |
| 12849 | AUTH_SYNC, |
| 12850 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12851 | 3, |
| 12852 | 1, |
| 12853 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12854 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12855 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12856 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12857 | {__LINE__, |
| 12858 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12859 | AUTH_SYNC, |
| 12860 | OK, |
| 12861 | kSecureServer, |
| 12862 | AUTH_ASYNC, |
| 12863 | OK, |
| 12864 | 3, |
| 12865 | 1, |
| 12866 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12867 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12868 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12869 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12870 | {__LINE__, |
| 12871 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12872 | AUTH_SYNC, |
| 12873 | OK, |
| 12874 | kSecureServer, |
| 12875 | AUTH_ASYNC, |
| 12876 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12877 | 3, |
| 12878 | 1, |
| 12879 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12880 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12881 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12882 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12883 | {__LINE__, |
| 12884 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12885 | AUTH_ASYNC, |
| 12886 | OK, |
| 12887 | kSecureServer, |
| 12888 | AUTH_ASYNC, |
| 12889 | OK, |
| 12890 | 3, |
| 12891 | 1, |
| 12892 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12893 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12894 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12895 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12896 | {__LINE__, |
| 12897 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12898 | AUTH_ASYNC, |
| 12899 | OK, |
| 12900 | kSecureServer, |
| 12901 | AUTH_ASYNC, |
| 12902 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12903 | 3, |
| 12904 | 1, |
| 12905 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12906 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12907 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12908 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12909 | {__LINE__, |
| 12910 | kProxy, |
| 12911 | AUTH_ASYNC, |
| 12912 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12913 | kSecureServer, |
| 12914 | AUTH_ASYNC, |
| 12915 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12916 | 4, |
| 12917 | 2, |
| 12918 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12919 | TestRound(kConnect, kProxyChallenge, OK), |
| 12920 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12921 | &kServerChallenge), |
| 12922 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12923 | }; |
| 12924 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12925 | for (const auto& test_config : test_configs) { |
| 12926 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12927 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12928 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12929 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12930 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12931 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12932 | |
| 12933 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12934 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12935 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12936 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12937 | std::string auth_challenge = "Mock realm=proxy"; |
| 12938 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12939 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12940 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12941 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12942 | empty_ssl_info, origin, |
| 12943 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12944 | auth_handler->SetGenerateExpectation( |
| 12945 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12946 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12947 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12948 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12949 | } |
| 12950 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12951 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12952 | std::string auth_challenge = "Mock realm=server"; |
| 12953 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12954 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12955 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12956 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12957 | empty_ssl_info, origin, |
| 12958 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12959 | auth_handler->SetGenerateExpectation( |
| 12960 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12961 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12962 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12963 | |
| 12964 | // The second handler always succeeds. It should only be used where there |
| 12965 | // are multiple auth sessions for server auth in the same network |
| 12966 | // transaction using the same auth scheme. |
| 12967 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12968 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12969 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12970 | empty_ssl_info, origin, |
| 12971 | NetLogWithSource()); |
| 12972 | second_handler->SetGenerateExpectation(true, OK); |
| 12973 | auth_factory->AddMockHandler(second_handler.release(), |
| 12974 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12975 | } |
| 12976 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12977 | session_deps_.proxy_service = |
| 12978 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12979 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12980 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12981 | } |
| 12982 | |
| 12983 | HttpRequestInfo request; |
| 12984 | request.method = "GET"; |
| 12985 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12988 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12989 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12990 | |
| 12991 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12992 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12993 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12994 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12995 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12996 | |
| 12997 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12998 | mock_reads.back().push_back(read_write_round.read); |
| 12999 | mock_writes.back().push_back(read_write_round.write); |
| 13000 | |
| 13001 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13002 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13003 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13004 | mock_reads.push_back(std::vector<MockRead>()); |
| 13005 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13006 | } |
| 13007 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13008 | if (read_write_round.extra_read) { |
| 13009 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13010 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13011 | if (read_write_round.extra_write) { |
| 13012 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13013 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13014 | |
| 13015 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13016 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13017 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13018 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13019 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13020 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13021 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13022 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13023 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 13024 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13025 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13026 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13027 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13028 | } |
| 13029 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13030 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13031 | // they are as well. |
| 13032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13033 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13034 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13035 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13036 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13037 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13038 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13039 | int rv; |
| 13040 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13041 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13042 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13043 | rv = trans.RestartWithAuth( |
| 13044 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13045 | } |
| 13046 | if (rv == ERR_IO_PENDING) |
| 13047 | rv = callback.WaitForResult(); |
| 13048 | |
| 13049 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13050 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13051 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13052 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13053 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13054 | continue; |
| 13055 | } |
| 13056 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13057 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13058 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13059 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13060 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13061 | } |
| 13062 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13063 | } |
| 13064 | } |
| 13065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13066 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13067 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13068 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13069 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13070 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13071 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13072 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 13073 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13074 | |
| 13075 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13076 | auth_handler->set_connection_based(true); |
| 13077 | std::string auth_challenge = "Mock realm=server"; |
| 13078 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13079 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13080 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13081 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13082 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13083 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13084 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13085 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13086 | int rv = OK; |
| 13087 | const HttpResponseInfo* response = NULL; |
| 13088 | HttpRequestInfo request; |
| 13089 | request.method = "GET"; |
| 13090 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13093 | |
| 13094 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13095 | // to validate that the TCP socket is not released to the pool between |
| 13096 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13097 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13098 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13099 | 50, // Max sockets for pool |
| 13100 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13101 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13102 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13103 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13104 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13105 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13107 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13108 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13109 | |
| 13110 | const MockWrite kGet( |
| 13111 | "GET / HTTP/1.1\r\n" |
| 13112 | "Host: www.example.com\r\n" |
| 13113 | "Connection: keep-alive\r\n\r\n"); |
| 13114 | const MockWrite kGetAuth( |
| 13115 | "GET / HTTP/1.1\r\n" |
| 13116 | "Host: www.example.com\r\n" |
| 13117 | "Connection: keep-alive\r\n" |
| 13118 | "Authorization: auth_token\r\n\r\n"); |
| 13119 | |
| 13120 | const MockRead kServerChallenge( |
| 13121 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13122 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13123 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13124 | "Content-Length: 14\r\n\r\n" |
| 13125 | "Unauthorized\r\n"); |
| 13126 | const MockRead kSuccess( |
| 13127 | "HTTP/1.1 200 OK\r\n" |
| 13128 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13129 | "Content-Length: 3\r\n\r\n" |
| 13130 | "Yes"); |
| 13131 | |
| 13132 | MockWrite writes[] = { |
| 13133 | // First round |
| 13134 | kGet, |
| 13135 | // Second round |
| 13136 | kGetAuth, |
| 13137 | // Third round |
| 13138 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13139 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13140 | kGetAuth, |
| 13141 | // Competing request |
| 13142 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13143 | }; |
| 13144 | MockRead reads[] = { |
| 13145 | // First round |
| 13146 | kServerChallenge, |
| 13147 | // Second round |
| 13148 | kServerChallenge, |
| 13149 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13150 | kServerChallenge, |
| 13151 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13152 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13153 | // Competing response |
| 13154 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13155 | }; |
| 13156 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 13157 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13158 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13159 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13160 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13161 | |
| 13162 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13163 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13164 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13165 | if (rv == ERR_IO_PENDING) |
| 13166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13167 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13168 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13169 | ASSERT_TRUE(response); |
| 13170 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13171 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13172 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13173 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13174 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13175 | // In between rounds, another request comes in for the same domain. |
| 13176 | // It should not be able to grab the TCP socket that trans has already |
| 13177 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13178 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13179 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13180 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13181 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13183 | // callback_compete.WaitForResult at this point would stall forever, |
| 13184 | // since the HttpNetworkTransaction does not release the request back to |
| 13185 | // the pool until after authentication completes. |
| 13186 | |
| 13187 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13188 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13189 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13190 | if (rv == ERR_IO_PENDING) |
| 13191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13192 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13193 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13194 | ASSERT_TRUE(response); |
| 13195 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13196 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13197 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13198 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13199 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13200 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13201 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13202 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13203 | if (rv == ERR_IO_PENDING) |
| 13204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13205 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13206 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13207 | ASSERT_TRUE(response); |
| 13208 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13209 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13210 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13211 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13212 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13213 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13214 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13215 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13216 | if (rv == ERR_IO_PENDING) |
| 13217 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13218 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13219 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13220 | ASSERT_TRUE(response); |
| 13221 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13222 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13223 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13224 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13225 | // auth handler should transition to a DONE state in concert with the remote |
| 13226 | // server. But that's not something we can test here with a mock handler. |
| 13227 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13228 | auth_handler->state()); |
| 13229 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13230 | // Read the body since the fourth round was successful. This will also |
| 13231 | // release the socket back to the pool. |
| 13232 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13233 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13234 | if (rv == ERR_IO_PENDING) |
| 13235 | rv = callback.WaitForResult(); |
| 13236 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13237 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13238 | EXPECT_EQ(0, rv); |
| 13239 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13240 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13241 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13242 | |
| 13243 | // The competing request can now finish. Wait for the headers and then |
| 13244 | // read the body. |
| 13245 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13246 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13247 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13248 | if (rv == ERR_IO_PENDING) |
| 13249 | rv = callback.WaitForResult(); |
| 13250 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13251 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13252 | EXPECT_EQ(0, rv); |
| 13253 | |
| 13254 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13255 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13256 | } |
| 13257 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13258 | // This tests the case that a request is issued via http instead of spdy after |
| 13259 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13260 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13261 | HttpRequestInfo request; |
| 13262 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13263 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13264 | |
| 13265 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13266 | MockWrite( |
| 13267 | "GET / HTTP/1.1\r\n" |
| 13268 | "Host: www.example.org\r\n" |
| 13269 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13270 | }; |
| 13271 | |
| 13272 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13273 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13274 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13275 | MockRead("\r\n"), |
| 13276 | MockRead("hello world"), |
| 13277 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13278 | }; |
| 13279 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13280 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13281 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13282 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13283 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13284 | |
| 13285 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 13286 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13287 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13288 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13289 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13290 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13292 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13293 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13294 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13295 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13297 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13299 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13300 | ASSERT_TRUE(response); |
| 13301 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13302 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13303 | |
| 13304 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13305 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13306 | EXPECT_EQ("hello world", response_data); |
| 13307 | |
| 13308 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13309 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13310 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13311 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13312 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13313 | // immediate server closing of the socket. |
| 13314 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13315 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13316 | HttpRequestInfo request; |
| 13317 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13318 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13319 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13320 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13321 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13322 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13323 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13324 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13325 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13326 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13327 | |
| 13328 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13329 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13330 | }; |
| 13331 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13332 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13333 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13334 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13335 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13336 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13337 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13340 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13341 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13343 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13344 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13345 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13346 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13347 | // it gets it. This is needed since the auth handler may get destroyed |
| 13348 | // before we get a chance to query it. |
| 13349 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13350 | public: |
| 13351 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13352 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13353 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13354 | |
| 13355 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13356 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13357 | const HttpRequestInfo* request, |
| 13358 | const CompletionCallback& callback, |
| 13359 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13360 | *url_ = request->url; |
| 13361 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13362 | credentials, request, callback, auth_token); |
| 13363 | } |
| 13364 | |
| 13365 | private: |
| 13366 | GURL* url_; |
| 13367 | }; |
| 13368 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13369 | // Test that if we cancel the transaction as the connection is completing, that |
| 13370 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13371 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13372 | // Setup everything about the connection to complete synchronously, so that |
| 13373 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13374 | // for is the callback from the HttpStreamRequest. |
| 13375 | // Then cancel the transaction. |
| 13376 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13377 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13378 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13379 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13380 | MockRead(SYNCHRONOUS, "hello world"), |
| 13381 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13382 | }; |
| 13383 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13384 | HttpRequestInfo request; |
| 13385 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13386 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13387 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13388 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13389 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13390 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13391 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13392 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13393 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13394 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13397 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13398 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13399 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13400 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13402 | trans.reset(); // Cancel the transaction here. |
| 13403 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13404 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13405 | } |
| 13406 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13407 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13408 | // stream is drained properly and added back to the socket pool. The main |
| 13409 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13410 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13411 | // deleted. |
| 13412 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13413 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13414 | MockRead data_reads[] = { |
| 13415 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13416 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13417 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13418 | MockRead(ASYNC, "1"), |
| 13419 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13420 | // HttpNetworkTransaction has been deleted. |
| 13421 | MockRead(ASYNC, "2"), |
| 13422 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13423 | }; |
| 13424 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13428 | |
| 13429 | { |
| 13430 | HttpRequestInfo request; |
| 13431 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13432 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13433 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13434 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13435 | TestCompletionCallback callback; |
| 13436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13439 | callback.WaitForResult(); |
| 13440 | |
| 13441 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13442 | ASSERT_TRUE(response); |
| 13443 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13444 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13445 | |
| 13446 | // The transaction and HttpRequestInfo are deleted. |
| 13447 | } |
| 13448 | |
| 13449 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13450 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13451 | |
| 13452 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13453 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13454 | } |
| 13455 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13456 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13457 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13458 | session_deps_.proxy_service = |
| 13459 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13460 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13461 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13463 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13464 | HttpRequestInfo request; |
| 13465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13466 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13467 | |
| 13468 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13469 | MockWrite( |
| 13470 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13471 | "Host: www.example.org\r\n" |
| 13472 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13473 | }; |
| 13474 | |
| 13475 | MockRead data_reads1[] = { |
| 13476 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13477 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13478 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13479 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13480 | }; |
| 13481 | |
| 13482 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13483 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13484 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13485 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13486 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13489 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13490 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13491 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13492 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13494 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13495 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13496 | |
| 13497 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13498 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13500 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13501 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13502 | |
| 13503 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13504 | EXPECT_EQ(200, response->headers->response_code()); |
| 13505 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13506 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13507 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13508 | HostPortPair::FromString("myproxy:70")), |
| 13509 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13510 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13511 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13512 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13513 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13514 | |
| 13515 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13516 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13517 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13518 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13519 | } |
| 13520 | |
| 13521 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13522 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13523 | session_deps_.proxy_service = |
| 13524 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13525 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13526 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13528 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13529 | HttpRequestInfo request; |
| 13530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13531 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13532 | |
| 13533 | // Since we have proxy, should try to establish tunnel. |
| 13534 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13535 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13536 | "Host: www.example.org:443\r\n" |
| 13537 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13538 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13539 | MockWrite("GET / HTTP/1.1\r\n" |
| 13540 | "Host: www.example.org\r\n" |
| 13541 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13542 | }; |
| 13543 | |
| 13544 | MockRead data_reads1[] = { |
| 13545 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13546 | |
| 13547 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13548 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13549 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13550 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13551 | }; |
| 13552 | |
| 13553 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13554 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13555 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13556 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13557 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13559 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13562 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13563 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13564 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13565 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13567 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13569 | |
| 13570 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13571 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13572 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13573 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13574 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13575 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13576 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13577 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13578 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13579 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13580 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13582 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13583 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13584 | |
| 13585 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13586 | EXPECT_EQ(200, response->headers->response_code()); |
| 13587 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13588 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13589 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13590 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13591 | HostPortPair::FromString("myproxy:70")), |
| 13592 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13593 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13594 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13595 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13596 | |
| 13597 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13598 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13599 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13600 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13601 | } |
| 13602 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13603 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13604 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13605 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13606 | session_deps_.proxy_service = |
| 13607 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13608 | BoundTestNetLog log; |
| 13609 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13611 | |
| 13612 | HttpRequestInfo request; |
| 13613 | request.method = "GET"; |
| 13614 | request.url = GURL("https://[::1]:443/"); |
| 13615 | |
| 13616 | // Since we have proxy, should try to establish tunnel. |
| 13617 | MockWrite data_writes1[] = { |
| 13618 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13619 | "Host: [::1]:443\r\n" |
| 13620 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13621 | |
| 13622 | MockWrite("GET / HTTP/1.1\r\n" |
| 13623 | "Host: [::1]\r\n" |
| 13624 | "Connection: keep-alive\r\n\r\n"), |
| 13625 | }; |
| 13626 | |
| 13627 | MockRead data_reads1[] = { |
| 13628 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13629 | |
| 13630 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13631 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13632 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13633 | MockRead(SYNCHRONOUS, OK), |
| 13634 | }; |
| 13635 | |
| 13636 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13637 | data_writes1, arraysize(data_writes1)); |
| 13638 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13639 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13640 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13641 | |
| 13642 | TestCompletionCallback callback1; |
| 13643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13645 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13646 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13648 | |
| 13649 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13650 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13651 | TestNetLogEntry::List entries; |
| 13652 | log.GetEntries(&entries); |
| 13653 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13654 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13655 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13656 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13657 | entries, pos, |
| 13658 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13659 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13661 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13662 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13663 | |
| 13664 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13665 | EXPECT_EQ(200, response->headers->response_code()); |
| 13666 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13667 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13668 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13669 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13670 | HostPortPair::FromString("myproxy:70")), |
| 13671 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13672 | |
| 13673 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13674 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13675 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13676 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13677 | } |
| 13678 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13679 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13680 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13681 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13682 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13683 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13684 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13686 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13687 | HttpRequestInfo request; |
| 13688 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13689 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13690 | |
| 13691 | // Since we have proxy, should try to establish tunnel. |
| 13692 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13693 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13694 | "Host: www.example.org:443\r\n" |
| 13695 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13696 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13697 | MockWrite("GET / HTTP/1.1\r\n" |
| 13698 | "Host: www.example.org\r\n" |
| 13699 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13700 | }; |
| 13701 | |
| 13702 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13703 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13704 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13705 | }; |
| 13706 | |
| 13707 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13708 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13709 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13710 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13713 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13717 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13719 | |
| 13720 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13721 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13722 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13723 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13724 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13725 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13726 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13727 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13728 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13729 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13730 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13731 | } |
| 13732 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13733 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13734 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13735 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13736 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13737 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13738 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13739 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13740 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13741 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13742 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13743 | }; |
| 13744 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13745 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13746 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13747 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13748 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13749 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13750 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13754 | |
| 13755 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13756 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13757 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13758 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13759 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13760 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13761 | |
| 13762 | HttpRequestInfo request; |
| 13763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13764 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13765 | |
| 13766 | // This is the important line that marks this as a preconnect. |
| 13767 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13768 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13770 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13771 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13772 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13774 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13775 | } |
| 13776 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13777 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13778 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13779 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13780 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13781 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13782 | request_info.url = GURL("https://www.example.com/"); |
| 13783 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13784 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13785 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13786 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13787 | MockWrite data_writes[] = { |
| 13788 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13789 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13790 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13793 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13796 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13797 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13798 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13799 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13800 | rv = callback.WaitForResult(); |
| 13801 | ASSERT_EQ(error, rv); |
| 13802 | } |
| 13803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13804 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13805 | // Just check a grab bag of cert errors. |
| 13806 | static const int kErrors[] = { |
| 13807 | ERR_CERT_COMMON_NAME_INVALID, |
| 13808 | ERR_CERT_AUTHORITY_INVALID, |
| 13809 | ERR_CERT_DATE_INVALID, |
| 13810 | }; |
| 13811 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13812 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13813 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13814 | } |
| 13815 | } |
| 13816 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13817 | // Ensure that a client certificate is removed from the SSL client auth |
| 13818 | // cache when: |
| 13819 | // 1) No proxy is involved. |
| 13820 | // 2) TLS False Start is disabled. |
| 13821 | // 3) The initial TLS handshake requests a client certificate. |
| 13822 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13823 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13824 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13825 | request_info.url = GURL("https://www.example.com/"); |
| 13826 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13827 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13828 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13829 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13830 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13831 | |
| 13832 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13833 | // CertificateRequest is received for the first time, the handshake will |
| 13834 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13835 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13836 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13838 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13839 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13840 | |
| 13841 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13842 | // False Start is not being used, the result of the SSL handshake will be |
| 13843 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13844 | // matches the result of a server sending a handshake_failure alert, |
| 13845 | // rather than a Finished message, because it requires a client |
| 13846 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13847 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13848 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13850 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13851 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13852 | |
| 13853 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13854 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13855 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13856 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13857 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13858 | // requiring a client certificate, this fallback handshake should also |
| 13859 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13860 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13861 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13863 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13864 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13865 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13866 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13867 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13868 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13869 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13870 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13871 | // requiring a client certificate, this fallback handshake should also |
| 13872 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13873 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13874 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13876 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13877 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13881 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13882 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13883 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13884 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13885 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13886 | |
| 13887 | // Complete the SSL handshake, which should abort due to requiring a |
| 13888 | // client certificate. |
| 13889 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13890 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13891 | |
| 13892 | // Indicate that no certificate should be supplied. From the perspective |
| 13893 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13894 | // certificate, so this is the same as supply a |
| 13895 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13896 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13897 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13898 | |
| 13899 | // Ensure the certificate was added to the client auth cache before |
| 13900 | // allowing the connection to continue restarting. |
| 13901 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13902 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13903 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13904 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13905 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13906 | |
| 13907 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13908 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13909 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13910 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13911 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13912 | |
| 13913 | // Ensure that the client certificate is removed from the cache on a |
| 13914 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13915 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13916 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13917 | } |
| 13918 | |
| 13919 | // Ensure that a client certificate is removed from the SSL client auth |
| 13920 | // cache when: |
| 13921 | // 1) No proxy is involved. |
| 13922 | // 2) TLS False Start is enabled. |
| 13923 | // 3) The initial TLS handshake requests a client certificate. |
| 13924 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13925 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13926 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13927 | request_info.url = GURL("https://www.example.com/"); |
| 13928 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13929 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13930 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13931 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13932 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13933 | |
| 13934 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13935 | // return successfully after reading up to the peer's Certificate message. |
| 13936 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13937 | // enqueue application data to be sent in the same packet as the |
| 13938 | // ChangeCipherSpec and Finished messages. |
| 13939 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13940 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13941 | // Finished messages. If there was an error negotiating with the peer, |
| 13942 | // such as due to the peer requiring a client certificate when none was |
| 13943 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13944 | // called. |
| 13945 | |
| 13946 | // Like the non-False Start case, when a client certificate is requested by |
| 13947 | // the peer, the handshake is aborted during the Connect() call. |
| 13948 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13949 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13950 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13951 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13952 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13953 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13954 | |
| 13955 | // When a client certificate is supplied, Connect() will not be aborted |
| 13956 | // when the peer requests the certificate. Instead, the handshake will |
| 13957 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13958 | // the socket. The handshake messages are not processed until Read() is |
| 13959 | // called, which then detects that the handshake was aborted, due to the |
| 13960 | // peer sending a handshake_failure because it requires a client |
| 13961 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13962 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13963 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13964 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13965 | MockRead data2_reads[] = { |
| 13966 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13967 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13968 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13969 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13970 | |
| 13971 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13972 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13973 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13974 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13975 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13976 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13977 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13978 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13979 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13980 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13981 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13982 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13983 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13985 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13986 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13987 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13988 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13989 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13990 | ssl_data5.cert_request_info = cert_request.get(); |
| 13991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13992 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13993 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13996 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13997 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13998 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13999 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14000 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14001 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14002 | |
| 14003 | // Complete the SSL handshake, which should abort due to requiring a |
| 14004 | // client certificate. |
| 14005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14006 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14007 | |
| 14008 | // Indicate that no certificate should be supplied. From the perspective |
| 14009 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14010 | // certificate, so this is the same as supply a |
| 14011 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14012 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14013 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14014 | |
| 14015 | // Ensure the certificate was added to the client auth cache before |
| 14016 | // allowing the connection to continue restarting. |
| 14017 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14018 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14019 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14020 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14021 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14022 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14023 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14024 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14025 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14026 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14027 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14028 | |
| 14029 | // Ensure that the client certificate is removed from the cache on a |
| 14030 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14031 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14032 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14033 | } |
| 14034 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14035 | // Ensure that a client certificate is removed from the SSL client auth |
| 14036 | // cache when: |
| 14037 | // 1) An HTTPS proxy is involved. |
| 14038 | // 3) The HTTPS proxy requests a client certificate. |
| 14039 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14040 | // proxy. |
| 14041 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14042 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14043 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14044 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14045 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14046 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14047 | |
| 14048 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14049 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14050 | |
| 14051 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14052 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14053 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14054 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14055 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14056 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14058 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14060 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14061 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14062 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14064 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14065 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14066 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14067 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14068 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14069 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14070 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14072 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14073 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14074 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14075 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14076 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14077 | requests[0].url = GURL("https://www.example.com/"); |
| 14078 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14079 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14080 | |
| 14081 | requests[1].url = GURL("http://www.example.com/"); |
| 14082 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14083 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14084 | |
| 14085 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14086 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14089 | |
| 14090 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14091 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14092 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14093 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14094 | |
| 14095 | // Complete the SSL handshake, which should abort due to requiring a |
| 14096 | // client certificate. |
| 14097 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14098 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14099 | |
| 14100 | // Indicate that no certificate should be supplied. From the perspective |
| 14101 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14102 | // certificate, so this is the same as supply a |
| 14103 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14104 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14105 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14106 | |
| 14107 | // Ensure the certificate was added to the client auth cache before |
| 14108 | // allowing the connection to continue restarting. |
| 14109 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14110 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14111 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14112 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14113 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14114 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14115 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14116 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14117 | HostPortPair("www.example.com", 443), &client_cert, |
| 14118 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14119 | |
| 14120 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14121 | // then consume ssl_data3, which should also fail. The result code is |
| 14122 | // checked against what ssl_data3 should return. |
| 14123 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14124 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14125 | |
| 14126 | // Now that the new handshake has failed, ensure that the client |
| 14127 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14128 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14129 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14130 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14131 | HostPortPair("www.example.com", 443), &client_cert, |
| 14132 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14133 | } |
| 14134 | } |
| 14135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14136 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14137 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14138 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14140 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14141 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14142 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14143 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14144 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14145 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14146 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14147 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14148 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14149 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14150 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14151 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14152 | SpdySerializedFrame host1_resp_body( |
| 14153 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14154 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14155 | SpdySerializedFrame host2_resp_body( |
| 14156 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14157 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14158 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14159 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14160 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14161 | }; |
| 14162 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14163 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14164 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14165 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14166 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14167 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14168 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14169 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14170 | HttpRequestInfo request1; |
| 14171 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14172 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14173 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14174 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14175 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14176 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14178 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14179 | |
| 14180 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14181 | ASSERT_TRUE(response); |
| 14182 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14183 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14184 | |
| 14185 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14186 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14187 | EXPECT_EQ("hello!", response_data); |
| 14188 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14189 | // Preload mail.example.com into HostCache. |
| 14190 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14191 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14192 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14193 | std::unique_ptr<HostResolver::Request> request; |
| 14194 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14195 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14196 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14199 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14200 | |
| 14201 | HttpRequestInfo request2; |
| 14202 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14203 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14204 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14205 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14206 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14207 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14209 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14210 | |
| 14211 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14212 | ASSERT_TRUE(response); |
| 14213 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14214 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14215 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14216 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14217 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14218 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14219 | } |
| 14220 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14221 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14222 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14223 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14224 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14225 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14226 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14227 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14228 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14229 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14230 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14231 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14232 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14233 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14234 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14235 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14236 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14237 | SpdySerializedFrame host1_resp_body( |
| 14238 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14239 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14240 | SpdySerializedFrame host2_resp_body( |
| 14241 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14242 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14243 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14244 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14245 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14246 | }; |
| 14247 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14248 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14249 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14250 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14251 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14252 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14253 | |
| 14254 | TestCompletionCallback callback; |
| 14255 | HttpRequestInfo request1; |
| 14256 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14257 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14258 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14259 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14260 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14261 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14263 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14264 | |
| 14265 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14266 | ASSERT_TRUE(response); |
| 14267 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14268 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14269 | |
| 14270 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14271 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14272 | EXPECT_EQ("hello!", response_data); |
| 14273 | |
| 14274 | HttpRequestInfo request2; |
| 14275 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14276 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14277 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14278 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14279 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14280 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14281 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14282 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14283 | |
| 14284 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14285 | ASSERT_TRUE(response); |
| 14286 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14287 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14288 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14289 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14290 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14291 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14292 | } |
| 14293 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14294 | // Regression test for https://crbug.com/546991. |
| 14295 | // The server might not be able to serve an IP pooled request, and might send a |
| 14296 | // 421 Misdirected Request response status to indicate this. |
| 14297 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14298 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14299 | // Two hosts resolve to the same IP address. |
| 14300 | const std::string ip_addr = "1.2.3.4"; |
| 14301 | IPAddress ip; |
| 14302 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14303 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14304 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14305 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14306 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14307 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14308 | |
| 14309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14310 | |
| 14311 | // Two requests on the first connection. |
| 14312 | SpdySerializedFrame req1( |
| 14313 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14314 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14315 | SpdySerializedFrame req2( |
| 14316 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14317 | SpdySerializedFrame rst( |
| 14318 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14319 | MockWrite writes1[] = { |
| 14320 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14321 | CreateMockWrite(rst, 6), |
| 14322 | }; |
| 14323 | |
| 14324 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14325 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14326 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14327 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14328 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14329 | SpdySerializedFrame resp2( |
| 14330 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14331 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14332 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14333 | |
| 14334 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14335 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14336 | arraysize(writes1)); |
| 14337 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14338 | |
| 14339 | AddSSLSocketData(); |
| 14340 | |
| 14341 | // Retry the second request on a second connection. |
| 14342 | SpdyTestUtil spdy_util2; |
| 14343 | SpdySerializedFrame req3( |
| 14344 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14345 | MockWrite writes2[] = { |
| 14346 | CreateMockWrite(req3, 0), |
| 14347 | }; |
| 14348 | |
| 14349 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14350 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14351 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14352 | MockRead(ASYNC, 0, 3)}; |
| 14353 | |
| 14354 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14355 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14356 | arraysize(writes2)); |
| 14357 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14358 | |
| 14359 | AddSSLSocketData(); |
| 14360 | |
| 14361 | // Preload mail.example.org into HostCache. |
| 14362 | HostPortPair host_port("mail.example.org", 443); |
| 14363 | HostResolver::RequestInfo resolve_info(host_port); |
| 14364 | AddressList ignored; |
| 14365 | std::unique_ptr<HostResolver::Request> request; |
| 14366 | TestCompletionCallback callback; |
| 14367 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14368 | &ignored, callback.callback(), |
| 14369 | &request, NetLogWithSource()); |
| 14370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14371 | rv = callback.WaitForResult(); |
| 14372 | EXPECT_THAT(rv, IsOk()); |
| 14373 | |
| 14374 | HttpRequestInfo request1; |
| 14375 | request1.method = "GET"; |
| 14376 | request1.url = GURL("https://www.example.org/"); |
| 14377 | request1.load_flags = 0; |
| 14378 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14379 | |
| 14380 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14382 | rv = callback.WaitForResult(); |
| 14383 | EXPECT_THAT(rv, IsOk()); |
| 14384 | |
| 14385 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14386 | ASSERT_TRUE(response); |
| 14387 | ASSERT_TRUE(response->headers); |
| 14388 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14389 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14390 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14391 | std::string response_data; |
| 14392 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14393 | EXPECT_EQ("hello!", response_data); |
| 14394 | |
| 14395 | HttpRequestInfo request2; |
| 14396 | request2.method = "GET"; |
| 14397 | request2.url = GURL("https://mail.example.org/"); |
| 14398 | request2.load_flags = 0; |
| 14399 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14400 | |
| 14401 | BoundTestNetLog log; |
| 14402 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14403 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14404 | rv = callback.WaitForResult(); |
| 14405 | EXPECT_THAT(rv, IsOk()); |
| 14406 | |
| 14407 | response = trans2.GetResponseInfo(); |
| 14408 | ASSERT_TRUE(response); |
| 14409 | ASSERT_TRUE(response->headers); |
| 14410 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14411 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14412 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14413 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14414 | EXPECT_EQ("hello!", response_data); |
| 14415 | |
| 14416 | TestNetLogEntry::List entries; |
| 14417 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14418 | ExpectLogContainsSomewhere( |
| 14419 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14420 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14421 | } |
| 14422 | |
| 14423 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14424 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14425 | // portions of the response. |
| 14426 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14427 | // Two hosts resolve to the same IP address. |
| 14428 | const std::string ip_addr = "1.2.3.4"; |
| 14429 | IPAddress ip; |
| 14430 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14431 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14432 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14433 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14434 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14435 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14436 | |
| 14437 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14438 | |
| 14439 | // Two requests on the first connection. |
| 14440 | SpdySerializedFrame req1( |
| 14441 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14442 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14443 | SpdySerializedFrame req2( |
| 14444 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14445 | SpdySerializedFrame rst( |
| 14446 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14447 | MockWrite writes1[] = { |
| 14448 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14449 | CreateMockWrite(rst, 6), |
| 14450 | }; |
| 14451 | |
| 14452 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14453 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14454 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14455 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14456 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14457 | SpdySerializedFrame resp2( |
| 14458 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14459 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14460 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14461 | |
| 14462 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14463 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14464 | arraysize(writes1)); |
| 14465 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14466 | |
| 14467 | AddSSLSocketData(); |
| 14468 | |
| 14469 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14470 | // Retry again. |
| 14471 | SpdyTestUtil spdy_util2; |
| 14472 | SpdySerializedFrame req3( |
| 14473 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14474 | MockWrite writes2[] = { |
| 14475 | CreateMockWrite(req3, 0), |
| 14476 | }; |
| 14477 | |
| 14478 | SpdySerializedFrame resp3( |
| 14479 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14480 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14481 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14482 | MockRead(ASYNC, 0, 3)}; |
| 14483 | |
| 14484 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14485 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14486 | arraysize(writes2)); |
| 14487 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14488 | |
| 14489 | AddSSLSocketData(); |
| 14490 | |
| 14491 | // Preload mail.example.org into HostCache. |
| 14492 | HostPortPair host_port("mail.example.org", 443); |
| 14493 | HostResolver::RequestInfo resolve_info(host_port); |
| 14494 | AddressList ignored; |
| 14495 | std::unique_ptr<HostResolver::Request> request; |
| 14496 | TestCompletionCallback callback; |
| 14497 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14498 | &ignored, callback.callback(), |
| 14499 | &request, NetLogWithSource()); |
| 14500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14501 | rv = callback.WaitForResult(); |
| 14502 | EXPECT_THAT(rv, IsOk()); |
| 14503 | |
| 14504 | HttpRequestInfo request1; |
| 14505 | request1.method = "GET"; |
| 14506 | request1.url = GURL("https://www.example.org/"); |
| 14507 | request1.load_flags = 0; |
| 14508 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14509 | |
| 14510 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14511 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14512 | rv = callback.WaitForResult(); |
| 14513 | EXPECT_THAT(rv, IsOk()); |
| 14514 | |
| 14515 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14516 | ASSERT_TRUE(response); |
| 14517 | ASSERT_TRUE(response->headers); |
| 14518 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14519 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14520 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14521 | std::string response_data; |
| 14522 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14523 | EXPECT_EQ("hello!", response_data); |
| 14524 | |
| 14525 | HttpRequestInfo request2; |
| 14526 | request2.method = "GET"; |
| 14527 | request2.url = GURL("https://mail.example.org/"); |
| 14528 | request2.load_flags = 0; |
| 14529 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14530 | |
| 14531 | BoundTestNetLog log; |
| 14532 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14534 | rv = callback.WaitForResult(); |
| 14535 | EXPECT_THAT(rv, IsOk()); |
| 14536 | |
| 14537 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14538 | // caller. |
| 14539 | response = trans2.GetResponseInfo(); |
| 14540 | ASSERT_TRUE(response); |
| 14541 | ASSERT_TRUE(response->headers); |
| 14542 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14543 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14544 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14545 | EXPECT_TRUE(response->ssl_info.cert); |
| 14546 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14547 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14548 | } |
| 14549 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14550 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14551 | public: |
| 14552 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14553 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14554 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14555 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14556 | int ResolveFromCache(const RequestInfo& info, |
| 14557 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14558 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14559 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14560 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14561 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14562 | return rv; |
| 14563 | } |
| 14564 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14565 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14566 | const HostPortPair host_port_; |
| 14567 | }; |
| 14568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14569 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14570 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14571 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14572 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14573 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14575 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14576 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14577 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14578 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14579 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14580 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14581 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14582 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14583 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14584 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14585 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14586 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14587 | SpdySerializedFrame host1_resp_body( |
| 14588 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14589 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14590 | SpdySerializedFrame host2_resp_body( |
| 14591 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14592 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14593 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14594 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14595 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14596 | }; |
| 14597 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14598 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14599 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14600 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14601 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14602 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14603 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14604 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14605 | HttpRequestInfo request1; |
| 14606 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14607 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14608 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14609 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14611 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14613 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14614 | |
| 14615 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14616 | ASSERT_TRUE(response); |
| 14617 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14618 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14619 | |
| 14620 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14621 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14622 | EXPECT_EQ("hello!", response_data); |
| 14623 | |
| 14624 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14625 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14626 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14627 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14628 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14629 | &ignored, callback.callback(), |
| 14630 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14632 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14633 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14634 | |
| 14635 | HttpRequestInfo request2; |
| 14636 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14637 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14638 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14639 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14640 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14641 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14642 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14643 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14644 | |
| 14645 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14646 | ASSERT_TRUE(response); |
| 14647 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14648 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14649 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14650 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14651 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14652 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14653 | } |
| 14654 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14655 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14656 | const std::string https_url = "https://www.example.org:8080/"; |
| 14657 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14658 | |
| 14659 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14660 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14661 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14662 | |
| 14663 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14664 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14665 | }; |
| 14666 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14667 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14668 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14669 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14670 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14671 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14672 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14673 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14674 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14675 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14676 | |
| 14677 | // HTTP GET for the HTTP URL |
| 14678 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14679 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14680 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14681 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14682 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14683 | }; |
| 14684 | |
| 14685 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14686 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14687 | MockRead(ASYNC, 2, "hello"), |
| 14688 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14689 | }; |
| 14690 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14691 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14692 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14693 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14694 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14695 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14696 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14698 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14701 | |
| 14702 | // Start the first transaction to set up the SpdySession |
| 14703 | HttpRequestInfo request1; |
| 14704 | request1.method = "GET"; |
| 14705 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14706 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14707 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14708 | TestCompletionCallback callback1; |
| 14709 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14710 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14711 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14712 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14713 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14714 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14715 | |
| 14716 | // Now, start the HTTP request |
| 14717 | HttpRequestInfo request2; |
| 14718 | request2.method = "GET"; |
| 14719 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14720 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14721 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14722 | TestCompletionCallback callback2; |
| 14723 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14724 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14725 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14726 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14727 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14728 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14729 | } |
| 14730 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14731 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14732 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14733 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14734 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14735 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14736 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14737 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14738 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14739 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14740 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14741 | |
| 14742 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14743 | // negotiated. |
| 14744 | StaticSocketDataProvider data; |
| 14745 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14746 | |
| 14747 | // 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] | 14748 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14749 | // mocked. This way the request relies on the alternate Job. |
| 14750 | StaticSocketDataProvider data_refused; |
| 14751 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14752 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14753 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14754 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14756 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14757 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14758 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14759 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14760 | http_server_properties->SetHttp2AlternativeService( |
| 14761 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14762 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14763 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14765 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14766 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14767 | TestCompletionCallback callback; |
| 14768 | |
| 14769 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14770 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14772 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14773 | } |
| 14774 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14775 | // 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] | 14776 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14777 | // succeeds, the request should succeed, even if the latter fails because |
| 14778 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14779 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14780 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14781 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14782 | |
| 14783 | // Negotiate HTTP/1.1 with alternative. |
| 14784 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14785 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14786 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14787 | |
| 14788 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14789 | // negotiated. |
| 14790 | StaticSocketDataProvider data; |
| 14791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14792 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14793 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14794 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14795 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14797 | |
| 14798 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14799 | MockWrite("GET / HTTP/1.1\r\n" |
| 14800 | "Host: www.example.org\r\n" |
| 14801 | "Connection: keep-alive\r\n\r\n"), |
| 14802 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14803 | "Host: www.example.org\r\n" |
| 14804 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14805 | }; |
| 14806 | |
| 14807 | MockRead http_reads[] = { |
| 14808 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14809 | MockRead("Content-Type: text/html\r\n"), |
| 14810 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14811 | MockRead("foobar"), |
| 14812 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14813 | MockRead("Content-Type: text/html\r\n"), |
| 14814 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14815 | MockRead("another"), |
| 14816 | }; |
| 14817 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14818 | http_writes, arraysize(http_writes)); |
| 14819 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14820 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14821 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14823 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14824 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14825 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14826 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14827 | http_server_properties->SetHttp2AlternativeService( |
| 14828 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14829 | |
| 14830 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14831 | HttpRequestInfo request1; |
| 14832 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14833 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14834 | request1.load_flags = 0; |
| 14835 | TestCompletionCallback callback1; |
| 14836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14837 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14838 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14839 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14840 | |
| 14841 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14842 | ASSERT_TRUE(response1); |
| 14843 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14844 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14845 | |
| 14846 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14847 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14848 | EXPECT_EQ("foobar", response_data1); |
| 14849 | |
| 14850 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14851 | // for alternative service. |
| 14852 | EXPECT_TRUE( |
| 14853 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14854 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14855 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14856 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14857 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14858 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14859 | HttpRequestInfo request2; |
| 14860 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14861 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14862 | request2.load_flags = 0; |
| 14863 | TestCompletionCallback callback2; |
| 14864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14865 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14866 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14867 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14868 | |
| 14869 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14870 | ASSERT_TRUE(response2); |
| 14871 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14872 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14873 | |
| 14874 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14875 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14876 | EXPECT_EQ("another", response_data2); |
| 14877 | } |
| 14878 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14879 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14880 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14881 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14882 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14883 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14884 | HostPortPair alternative("alternative.example.org", 443); |
| 14885 | std::string origin_url = "https://origin.example.org:443"; |
| 14886 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14887 | |
| 14888 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14889 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14890 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14891 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14892 | |
| 14893 | // HTTP/1.1 data for |request1| and |request2|. |
| 14894 | MockWrite http_writes[] = { |
| 14895 | MockWrite( |
| 14896 | "GET / HTTP/1.1\r\n" |
| 14897 | "Host: alternative.example.org\r\n" |
| 14898 | "Connection: keep-alive\r\n\r\n"), |
| 14899 | MockWrite( |
| 14900 | "GET / HTTP/1.1\r\n" |
| 14901 | "Host: alternative.example.org\r\n" |
| 14902 | "Connection: keep-alive\r\n\r\n"), |
| 14903 | }; |
| 14904 | |
| 14905 | MockRead http_reads[] = { |
| 14906 | MockRead( |
| 14907 | "HTTP/1.1 200 OK\r\n" |
| 14908 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14909 | "Content-Length: 40\r\n\r\n" |
| 14910 | "first HTTP/1.1 response from alternative"), |
| 14911 | MockRead( |
| 14912 | "HTTP/1.1 200 OK\r\n" |
| 14913 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14914 | "Content-Length: 41\r\n\r\n" |
| 14915 | "second HTTP/1.1 response from alternative"), |
| 14916 | }; |
| 14917 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14918 | http_writes, arraysize(http_writes)); |
| 14919 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14920 | |
| 14921 | // This test documents that an alternate Job should not pool to an already |
| 14922 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14923 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14924 | StaticSocketDataProvider data_refused; |
| 14925 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14926 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14927 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14928 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14930 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14931 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14932 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14933 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14934 | http_server_properties->SetHttp2AlternativeService( |
| 14935 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14936 | |
| 14937 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14938 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14939 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14940 | request1.method = "GET"; |
| 14941 | request1.url = GURL(alternative_url); |
| 14942 | request1.load_flags = 0; |
| 14943 | TestCompletionCallback callback1; |
| 14944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14945 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14946 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14947 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14948 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14949 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14950 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14951 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14952 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14953 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14954 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14955 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14956 | |
| 14957 | // Request for origin.example.org, which has an alternative service. This |
| 14958 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14959 | // 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] | 14960 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14961 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14962 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14963 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14964 | request2.method = "GET"; |
| 14965 | request2.url = GURL(origin_url); |
| 14966 | request2.load_flags = 0; |
| 14967 | TestCompletionCallback callback2; |
| 14968 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14969 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14970 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14971 | |
| 14972 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14973 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14974 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14975 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14976 | request3.method = "GET"; |
| 14977 | request3.url = GURL(alternative_url); |
| 14978 | request3.load_flags = 0; |
| 14979 | TestCompletionCallback callback3; |
| 14980 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14981 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14982 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14983 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14984 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14985 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14986 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14987 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14988 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14989 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14990 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14991 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14992 | } |
| 14993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14994 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14995 | const std::string https_url = "https://www.example.org:8080/"; |
| 14996 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14997 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14998 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14999 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15000 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15001 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15002 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15003 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15004 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15005 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15006 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15007 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15008 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15009 | |
| 15010 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 15011 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 15012 | req2_block[kHttp2MethodHeader] = "GET"; |
| 15013 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15014 | req2_block[kHttp2SchemeHeader] = "http"; |
| 15015 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15016 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15017 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15018 | |
| 15019 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15020 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15021 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15022 | }; |
| 15023 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15024 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15025 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15026 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15027 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15028 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15029 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15030 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15031 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15032 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15033 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15034 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15035 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15036 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15037 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15038 | CreateMockRead(wrapped_resp1, 4), |
| 15039 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15040 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15041 | CreateMockRead(resp2, 8), |
| 15042 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15043 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15044 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15045 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15046 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15047 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15048 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15049 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15050 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 15051 | session_deps_.proxy_service = |
| 15052 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15053 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15054 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15055 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15056 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15058 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15059 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15061 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15062 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15063 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15064 | |
| 15065 | // Start the first transaction to set up the SpdySession |
| 15066 | HttpRequestInfo request1; |
| 15067 | request1.method = "GET"; |
| 15068 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15069 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15070 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15071 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15072 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15073 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15074 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15075 | data1.RunUntilPaused(); |
| 15076 | base::RunLoop().RunUntilIdle(); |
| 15077 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15078 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15079 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15080 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15081 | LoadTimingInfo load_timing_info1; |
| 15082 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15083 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15084 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15085 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15086 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15087 | HttpRequestInfo request2; |
| 15088 | request2.method = "GET"; |
| 15089 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15090 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15091 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15092 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15093 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15094 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15095 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15096 | data1.RunUntilPaused(); |
| 15097 | base::RunLoop().RunUntilIdle(); |
| 15098 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15099 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15100 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15101 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15102 | |
| 15103 | LoadTimingInfo load_timing_info2; |
| 15104 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15105 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15106 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15107 | // HTTP requests over a SPDY session should have a different connection |
| 15108 | // socket_log_id than requests over a tunnel. |
| 15109 | 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] | 15110 | } |
| 15111 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15112 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15113 | // that we do not pool other origins that resolve to the same IP when |
| 15114 | // the certificate does not match the new origin. |
| 15115 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15116 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15117 | const std::string url1 = "http://www.example.org/"; |
| 15118 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15119 | const std::string ip_addr = "1.2.3.4"; |
| 15120 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15121 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15122 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15123 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15124 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 15125 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15126 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15127 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15128 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15129 | |
| 15130 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15131 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15132 | }; |
| 15133 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15134 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15135 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15136 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15137 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15138 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15139 | }; |
| 15140 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15141 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 15142 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15143 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15144 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15145 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15146 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15147 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15148 | |
| 15149 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15150 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15151 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15152 | |
| 15153 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15154 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15155 | }; |
| 15156 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15157 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15158 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 15159 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15160 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15161 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15162 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15163 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15164 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15165 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15166 | |
| 15167 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15168 | // all others direct. |
| 15169 | ProxyConfig proxy_config; |
| 15170 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15171 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 15172 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15173 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15174 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15175 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15176 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15177 | // Load a valid cert. Note, that this does not need to |
| 15178 | // be valid for proxy because the MockSSLClientSocket does |
| 15179 | // not actually verify it. But SpdySession will use this |
| 15180 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15181 | ssl1.ssl_info.cert = |
| 15182 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15183 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15184 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15186 | |
| 15187 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15188 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15189 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15190 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15191 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15192 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15193 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15194 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15195 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15196 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15197 | |
| 15198 | // Start the first transaction to set up the SpdySession |
| 15199 | HttpRequestInfo request1; |
| 15200 | request1.method = "GET"; |
| 15201 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15202 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15203 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15204 | TestCompletionCallback callback1; |
| 15205 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15206 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15207 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15208 | data1.RunUntilPaused(); |
| 15209 | base::RunLoop().RunUntilIdle(); |
| 15210 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15211 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15212 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15213 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15214 | |
| 15215 | // Now, start the HTTP request |
| 15216 | HttpRequestInfo request2; |
| 15217 | request2.method = "GET"; |
| 15218 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15219 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15220 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15221 | TestCompletionCallback callback2; |
| 15222 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15223 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15224 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15225 | |
| 15226 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15227 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15228 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15229 | } |
| 15230 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15231 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15232 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15233 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15234 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15235 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15236 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15237 | |
| 15238 | MockRead reads1[] = { |
| 15239 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15240 | }; |
| 15241 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15242 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15243 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15244 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15245 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15246 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15247 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15248 | }; |
| 15249 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15250 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15251 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15252 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15253 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15254 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15255 | }; |
| 15256 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15257 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 15258 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15259 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15260 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15261 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15262 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15263 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15264 | |
| 15265 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15266 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15268 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15269 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15270 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15271 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15272 | |
| 15273 | // Start the first transaction to set up the SpdySession and verify that |
| 15274 | // connection was closed. |
| 15275 | HttpRequestInfo request1; |
| 15276 | request1.method = "GET"; |
| 15277 | request1.url = GURL(https_url); |
| 15278 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15279 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15280 | TestCompletionCallback callback1; |
| 15281 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15282 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15283 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15284 | |
| 15285 | // Now, start the second request and make sure it succeeds. |
| 15286 | HttpRequestInfo request2; |
| 15287 | request2.method = "GET"; |
| 15288 | request2.url = GURL(https_url); |
| 15289 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15290 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15291 | TestCompletionCallback callback2; |
| 15292 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15293 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15294 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15295 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15296 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15297 | } |
| 15298 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15299 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15300 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15301 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15302 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15303 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15304 | |
| 15305 | // Use two different hosts with different IPs so they don't get pooled. |
| 15306 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15307 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15309 | |
| 15310 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15311 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15312 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15313 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15314 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15316 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15317 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15318 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15319 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15320 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15321 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15322 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15323 | SpdySerializedFrame host1_resp_body( |
| 15324 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15325 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15326 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15327 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15328 | }; |
| 15329 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15330 | // Use a separate test instance for the separate SpdySession that will be |
| 15331 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15332 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15333 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15334 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15335 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15336 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15337 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15338 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15339 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15340 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15341 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15342 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15343 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15344 | SpdySerializedFrame host2_resp_body( |
| 15345 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15346 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15347 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15348 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15349 | }; |
| 15350 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15351 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15352 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15353 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15354 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15355 | |
| 15356 | MockWrite http_write[] = { |
| 15357 | MockWrite("GET / HTTP/1.1\r\n" |
| 15358 | "Host: www.a.com\r\n" |
| 15359 | "Connection: keep-alive\r\n\r\n"), |
| 15360 | }; |
| 15361 | |
| 15362 | MockRead http_read[] = { |
| 15363 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15364 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15365 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15366 | MockRead("hello!"), |
| 15367 | }; |
| 15368 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15369 | http_write, arraysize(http_write)); |
| 15370 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15371 | |
| 15372 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15373 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15374 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15375 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15376 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15377 | |
| 15378 | TestCompletionCallback callback; |
| 15379 | HttpRequestInfo request1; |
| 15380 | request1.method = "GET"; |
| 15381 | request1.url = GURL("https://www.a.com/"); |
| 15382 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15383 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15384 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15385 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15386 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15387 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15388 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15389 | |
| 15390 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15391 | ASSERT_TRUE(response); |
| 15392 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15393 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15394 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15395 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15396 | |
| 15397 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15398 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15399 | EXPECT_EQ("hello!", response_data); |
| 15400 | trans.reset(); |
| 15401 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15402 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15403 | |
| 15404 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15405 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15406 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15407 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15408 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15409 | HttpRequestInfo request2; |
| 15410 | request2.method = "GET"; |
| 15411 | request2.url = GURL("https://www.b.com/"); |
| 15412 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15413 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15414 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15415 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15416 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15418 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15419 | |
| 15420 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15421 | ASSERT_TRUE(response); |
| 15422 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15423 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15424 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15425 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15426 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15427 | EXPECT_EQ("hello!", response_data); |
| 15428 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15429 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15430 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15431 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15432 | |
| 15433 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15434 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15435 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15436 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15437 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15438 | HttpRequestInfo request3; |
| 15439 | request3.method = "GET"; |
| 15440 | request3.url = GURL("http://www.a.com/"); |
| 15441 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15442 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15443 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15444 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15445 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15447 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15448 | |
| 15449 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15450 | ASSERT_TRUE(response); |
| 15451 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15452 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15453 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15454 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15455 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15456 | EXPECT_EQ("hello!", response_data); |
| 15457 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15458 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15459 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15460 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15461 | } |
| 15462 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15463 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15464 | HttpRequestInfo request; |
| 15465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15466 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15467 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15470 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15471 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15472 | StaticSocketDataProvider data; |
| 15473 | data.set_connect_data(mock_connect); |
| 15474 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15475 | |
| 15476 | TestCompletionCallback callback; |
| 15477 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15478 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15480 | |
| 15481 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15482 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15483 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15484 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15485 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15486 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15487 | |
| 15488 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15489 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15490 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15491 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15492 | |
| 15493 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15494 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15495 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15496 | } |
| 15497 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15498 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15499 | HttpRequestInfo request; |
| 15500 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15501 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15505 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15506 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15507 | StaticSocketDataProvider data; |
| 15508 | data.set_connect_data(mock_connect); |
| 15509 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15510 | |
| 15511 | TestCompletionCallback callback; |
| 15512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15513 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15515 | |
| 15516 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15517 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15518 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15519 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15520 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15521 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15522 | |
| 15523 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15524 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15525 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15526 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15527 | |
| 15528 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15529 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15530 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15531 | } |
| 15532 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15533 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15534 | HttpRequestInfo request; |
| 15535 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15536 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15537 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15538 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15539 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15540 | |
| 15541 | MockWrite data_writes[] = { |
| 15542 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15543 | }; |
| 15544 | MockRead data_reads[] = { |
| 15545 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15546 | }; |
| 15547 | |
| 15548 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15549 | data_writes, arraysize(data_writes)); |
| 15550 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15551 | |
| 15552 | TestCompletionCallback callback; |
| 15553 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15554 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15556 | |
| 15557 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15558 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15559 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15560 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15561 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15562 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15563 | } |
| 15564 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15565 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15566 | HttpRequestInfo request; |
| 15567 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15568 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15569 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15570 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15571 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15572 | |
| 15573 | MockWrite data_writes[] = { |
| 15574 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15575 | }; |
| 15576 | MockRead data_reads[] = { |
| 15577 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15578 | }; |
| 15579 | |
| 15580 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15581 | data_writes, arraysize(data_writes)); |
| 15582 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15583 | |
| 15584 | TestCompletionCallback callback; |
| 15585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15587 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15588 | |
| 15589 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15590 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15591 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15592 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15593 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15594 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15595 | } |
| 15596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15597 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15598 | HttpRequestInfo request; |
| 15599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15600 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15604 | |
| 15605 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15606 | MockWrite( |
| 15607 | "GET / HTTP/1.1\r\n" |
| 15608 | "Host: www.example.org\r\n" |
| 15609 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15610 | }; |
| 15611 | MockRead data_reads[] = { |
| 15612 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15613 | }; |
| 15614 | |
| 15615 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15616 | data_writes, arraysize(data_writes)); |
| 15617 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15618 | |
| 15619 | TestCompletionCallback callback; |
| 15620 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15621 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15622 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15623 | |
| 15624 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15625 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15626 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15627 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15628 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15629 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15630 | } |
| 15631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15632 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15633 | HttpRequestInfo request; |
| 15634 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15635 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15639 | |
| 15640 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15641 | MockWrite( |
| 15642 | "GET / HTTP/1.1\r\n" |
| 15643 | "Host: www.example.org\r\n" |
| 15644 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15645 | }; |
| 15646 | MockRead data_reads[] = { |
| 15647 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15648 | }; |
| 15649 | |
| 15650 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15651 | data_writes, arraysize(data_writes)); |
| 15652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15653 | |
| 15654 | TestCompletionCallback callback; |
| 15655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15656 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15658 | |
| 15659 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15660 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15661 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15662 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15663 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15664 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15665 | } |
| 15666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15667 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15668 | HttpRequestInfo request; |
| 15669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15670 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15671 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15672 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15675 | |
| 15676 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15677 | MockWrite( |
| 15678 | "GET / HTTP/1.1\r\n" |
| 15679 | "Host: www.example.org\r\n" |
| 15680 | "Connection: keep-alive\r\n" |
| 15681 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15682 | }; |
| 15683 | MockRead data_reads[] = { |
| 15684 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15685 | "Content-Length: 5\r\n\r\n" |
| 15686 | "hello"), |
| 15687 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15688 | }; |
| 15689 | |
| 15690 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15691 | data_writes, arraysize(data_writes)); |
| 15692 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15693 | |
| 15694 | TestCompletionCallback callback; |
| 15695 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15696 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15697 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15698 | |
| 15699 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15700 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15701 | |
| 15702 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15703 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15704 | std::string foo; |
| 15705 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15706 | EXPECT_EQ("bar", foo); |
| 15707 | } |
| 15708 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15709 | namespace { |
| 15710 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15711 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15712 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15713 | public base::SupportsWeakPtr<FakeStream> { |
| 15714 | public: |
| 15715 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15716 | ~FakeStream() override = default; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15717 | |
| 15718 | RequestPriority priority() const { return priority_; } |
| 15719 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15720 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15721 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15722 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15723 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15724 | return ERR_IO_PENDING; |
| 15725 | } |
| 15726 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15727 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15728 | HttpResponseInfo* response, |
| 15729 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15730 | ADD_FAILURE(); |
| 15731 | return ERR_UNEXPECTED; |
| 15732 | } |
| 15733 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15734 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15735 | ADD_FAILURE(); |
| 15736 | return ERR_UNEXPECTED; |
| 15737 | } |
| 15738 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15739 | int ReadResponseBody(IOBuffer* buf, |
| 15740 | int buf_len, |
| 15741 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15742 | ADD_FAILURE(); |
| 15743 | return ERR_UNEXPECTED; |
| 15744 | } |
| 15745 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15746 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15747 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15748 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15749 | ADD_FAILURE(); |
| 15750 | return false; |
| 15751 | } |
| 15752 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15753 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15754 | ADD_FAILURE(); |
| 15755 | return false; |
| 15756 | } |
| 15757 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15758 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15759 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15760 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15761 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15762 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15763 | ADD_FAILURE(); |
| 15764 | return 0; |
| 15765 | } |
| 15766 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15767 | int64_t GetTotalSentBytes() const override { |
| 15768 | ADD_FAILURE(); |
| 15769 | return 0; |
| 15770 | } |
| 15771 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15772 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15773 | ADD_FAILURE(); |
| 15774 | return false; |
| 15775 | } |
| 15776 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15777 | bool GetAlternativeService( |
| 15778 | AlternativeService* alternative_service) const override { |
| 15779 | ADD_FAILURE(); |
| 15780 | return false; |
| 15781 | } |
| 15782 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15783 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15784 | |
| 15785 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15786 | ADD_FAILURE(); |
| 15787 | } |
| 15788 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15789 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15790 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15791 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15792 | TokenBindingType tb_type, |
| 15793 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15794 | ADD_FAILURE(); |
| 15795 | return ERR_NOT_IMPLEMENTED; |
| 15796 | } |
| 15797 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15798 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15799 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15800 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15801 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15802 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15803 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15804 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15805 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15806 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15807 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15808 | private: |
| 15809 | RequestPriority priority_; |
| 15810 | |
| 15811 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15812 | }; |
| 15813 | |
| 15814 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15815 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15816 | class FakeStreamRequest : public HttpStreamRequest, |
| 15817 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15818 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15819 | FakeStreamRequest(RequestPriority priority, |
| 15820 | HttpStreamRequest::Delegate* delegate) |
| 15821 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15822 | delegate_(delegate), |
| 15823 | websocket_stream_create_helper_(NULL) {} |
| 15824 | |
| 15825 | FakeStreamRequest(RequestPriority priority, |
| 15826 | HttpStreamRequest::Delegate* delegate, |
| 15827 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15828 | : priority_(priority), |
| 15829 | delegate_(delegate), |
| 15830 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15831 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15832 | ~FakeStreamRequest() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15833 | |
| 15834 | RequestPriority priority() const { return priority_; } |
| 15835 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15836 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15837 | websocket_stream_create_helper() const { |
| 15838 | return websocket_stream_create_helper_; |
| 15839 | } |
| 15840 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15841 | // Create a new FakeStream and pass it to the request's |
| 15842 | // delegate. Returns a weak pointer to the FakeStream. |
| 15843 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15844 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15845 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15846 | // immediately delete |fake_stream|. |
| 15847 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15848 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15849 | return weak_stream; |
| 15850 | } |
| 15851 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15852 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15853 | ADD_FAILURE(); |
| 15854 | return ERR_UNEXPECTED; |
| 15855 | } |
| 15856 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15857 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15858 | ADD_FAILURE(); |
| 15859 | return LoadState(); |
| 15860 | } |
| 15861 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15862 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15863 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15864 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15865 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15866 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15867 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15868 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15869 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15870 | const ConnectionAttempts& connection_attempts() const override { |
| 15871 | static ConnectionAttempts no_attempts; |
| 15872 | return no_attempts; |
| 15873 | } |
| 15874 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15875 | private: |
| 15876 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15877 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15878 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15879 | |
| 15880 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15881 | }; |
| 15882 | |
| 15883 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15884 | class FakeStreamFactory : public HttpStreamFactory { |
| 15885 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15886 | FakeStreamFactory() = default; |
| 15887 | ~FakeStreamFactory() override = default; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15888 | |
| 15889 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15890 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15891 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15892 | return last_stream_request_; |
| 15893 | } |
| 15894 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15895 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15896 | const HttpRequestInfo& info, |
| 15897 | RequestPriority priority, |
| 15898 | const SSLConfig& server_ssl_config, |
| 15899 | const SSLConfig& proxy_ssl_config, |
| 15900 | HttpStreamRequest::Delegate* delegate, |
| 15901 | bool enable_ip_based_pooling, |
| 15902 | bool enable_alternative_services, |
| 15903 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15904 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15905 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15906 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15907 | } |
| 15908 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15909 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15910 | const HttpRequestInfo& info, |
| 15911 | RequestPriority priority, |
| 15912 | const SSLConfig& server_ssl_config, |
| 15913 | const SSLConfig& proxy_ssl_config, |
| 15914 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15915 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15916 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15917 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15918 | NOTREACHED(); |
| 15919 | return nullptr; |
| 15920 | } |
| 15921 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15922 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15923 | const HttpRequestInfo& info, |
| 15924 | RequestPriority priority, |
| 15925 | const SSLConfig& server_ssl_config, |
| 15926 | const SSLConfig& proxy_ssl_config, |
| 15927 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15928 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15929 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15930 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15931 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15932 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15933 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15934 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15935 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15936 | } |
| 15937 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15938 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15939 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15940 | ADD_FAILURE(); |
| 15941 | } |
| 15942 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15943 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15944 | ADD_FAILURE(); |
| 15945 | return NULL; |
| 15946 | } |
| 15947 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15948 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15949 | const std::string& parent_absolute_name) const override { |
| 15950 | ADD_FAILURE(); |
| 15951 | } |
| 15952 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15953 | private: |
| 15954 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15955 | |
| 15956 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15957 | }; |
| 15958 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15959 | // TODO(ricea): Maybe unify this with the one in |
| 15960 | // url_request_http_job_unittest.cc ? |
| 15961 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15962 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15963 | FakeWebSocketBasicHandshakeStream( |
| 15964 | std::unique_ptr<ClientSocketHandle> connection, |
| 15965 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15966 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15967 | |
| 15968 | // Fake implementation of HttpStreamBase methods. |
| 15969 | // This ends up being quite "real" because this object has to really send data |
| 15970 | // on the mock socket. It might be easier to use the real implementation, but |
| 15971 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15972 | // difficult. |
| 15973 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15974 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15975 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15976 | const CompletionCallback& callback) override { |
| 15977 | state_.Initialize(request_info, priority, net_log, callback); |
| 15978 | return OK; |
| 15979 | } |
| 15980 | |
| 15981 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15982 | HttpResponseInfo* response, |
| 15983 | const CompletionCallback& callback) override { |
| 15984 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15985 | response, callback); |
| 15986 | } |
| 15987 | |
| 15988 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15989 | return parser()->ReadResponseHeaders(callback); |
| 15990 | } |
| 15991 | |
| 15992 | int ReadResponseBody(IOBuffer* buf, |
| 15993 | int buf_len, |
| 15994 | const CompletionCallback& callback) override { |
| 15995 | NOTREACHED(); |
| 15996 | return ERR_IO_PENDING; |
| 15997 | } |
| 15998 | |
| 15999 | void Close(bool not_reusable) override { |
| 16000 | if (parser()) |
| 16001 | parser()->Close(true); |
| 16002 | } |
| 16003 | |
| 16004 | bool IsResponseBodyComplete() const override { |
| 16005 | NOTREACHED(); |
| 16006 | return false; |
| 16007 | } |
| 16008 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16009 | bool IsConnectionReused() const override { |
| 16010 | NOTREACHED(); |
| 16011 | return false; |
| 16012 | } |
| 16013 | void SetConnectionReused() override { NOTREACHED(); } |
| 16014 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 16015 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16016 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 16017 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16018 | NOTREACHED(); |
| 16019 | return 0; |
| 16020 | } |
| 16021 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 16022 | int64_t GetTotalSentBytes() const override { |
| 16023 | NOTREACHED(); |
| 16024 | return 0; |
| 16025 | } |
| 16026 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16027 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 16028 | NOTREACHED(); |
| 16029 | return false; |
| 16030 | } |
| 16031 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 16032 | bool GetAlternativeService( |
| 16033 | AlternativeService* alternative_service) const override { |
| 16034 | ADD_FAILURE(); |
| 16035 | return false; |
| 16036 | } |
| 16037 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 16038 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16039 | |
| 16040 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 16041 | NOTREACHED(); |
| 16042 | } |
| 16043 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16044 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 16045 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 16046 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 16047 | TokenBindingType tb_type, |
| 16048 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16049 | ADD_FAILURE(); |
| 16050 | return ERR_NOT_IMPLEMENTED; |
| 16051 | } |
| 16052 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16053 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 16054 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 16055 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 16056 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16057 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 16058 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16059 | HttpStream* RenewStreamForAuth() override { |
| 16060 | NOTREACHED(); |
| 16061 | return nullptr; |
| 16062 | } |
| 16063 | |
| 16064 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16065 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16066 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16067 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16068 | } |
| 16069 | |
| 16070 | private: |
| 16071 | HttpStreamParser* parser() const { return state_.parser(); } |
| 16072 | HttpBasicState state_; |
| 16073 | |
| 16074 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 16075 | }; |
| 16076 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16077 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 16078 | // worth doing. |
| 16079 | class FakeWebSocketStreamCreateHelper : |
| 16080 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 16081 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16082 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16083 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 16084 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16085 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 16086 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16087 | } |
| 16088 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 16089 | ~FakeWebSocketStreamCreateHelper() override = default; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16090 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16091 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16092 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16093 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16094 | } |
| 16095 | }; |
| 16096 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16097 | } // namespace |
| 16098 | |
| 16099 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 16100 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16101 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16103 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16104 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16105 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16106 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16107 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16108 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16109 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16110 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16111 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16112 | TestCompletionCallback callback; |
| 16113 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16114 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16115 | |
| 16116 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16117 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16118 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16119 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16120 | } |
| 16121 | |
| 16122 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16123 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16124 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16126 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16127 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16128 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16129 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16130 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16131 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16132 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16133 | TestCompletionCallback callback; |
| 16134 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16135 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16136 | |
| 16137 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16138 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16139 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16140 | EXPECT_EQ(LOW, fake_request->priority()); |
| 16141 | |
| 16142 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16143 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 16144 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 16145 | } |
| 16146 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16147 | // Make sure that HttpNetworkTransaction passes on its priority |
| 16148 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16149 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16151 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16152 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16153 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16154 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16155 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16156 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16157 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16158 | TestCompletionCallback callback; |
| 16159 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16160 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16161 | |
| 16162 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16163 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16164 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16165 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16166 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 16167 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 16168 | |
| 16169 | trans.SetPriority(LOWEST); |
| 16170 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 16171 | } |
| 16172 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16173 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16174 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 16175 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 16176 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16177 | std::string test_cases[] = {"ws://www.example.org/", |
| 16178 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16179 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 16181 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16182 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 16183 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
Bence Béky | 8cae04e | 2018-01-15 18:37:06 | [diff] [blame] | 16184 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16185 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16186 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16187 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16188 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 16189 | &websocket_stream_create_helper); |
| 16190 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16191 | TestCompletionCallback callback; |
| 16192 | request.method = "GET"; |
| 16193 | request.url = GURL(test_cases[i]); |
| 16194 | |
| 16195 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16196 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16197 | |
| 16198 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 16199 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16200 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 16201 | EXPECT_EQ(&websocket_stream_create_helper, |
| 16202 | fake_request->websocket_stream_create_helper()); |
| 16203 | } |
| 16204 | } |
| 16205 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16206 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16207 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16208 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16209 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16210 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16211 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16212 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16213 | |
| 16214 | // Set up SSL request. |
| 16215 | |
| 16216 | HttpRequestInfo ssl_request; |
| 16217 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16218 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16219 | |
| 16220 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16221 | MockWrite( |
| 16222 | "GET / HTTP/1.1\r\n" |
| 16223 | "Host: www.example.org\r\n" |
| 16224 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16225 | }; |
| 16226 | MockRead ssl_reads[] = { |
| 16227 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16228 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16229 | MockRead("hello world"), |
| 16230 | MockRead(SYNCHRONOUS, OK), |
| 16231 | }; |
| 16232 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 16233 | ssl_writes, arraysize(ssl_writes)); |
| 16234 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16235 | |
| 16236 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16237 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16238 | |
| 16239 | // Set up HTTP request. |
| 16240 | |
| 16241 | HttpRequestInfo http_request; |
| 16242 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16243 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16244 | |
| 16245 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16246 | MockWrite( |
| 16247 | "GET / HTTP/1.1\r\n" |
| 16248 | "Host: www.example.org\r\n" |
| 16249 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16250 | }; |
| 16251 | MockRead http_reads[] = { |
| 16252 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16253 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16254 | MockRead("falafel"), |
| 16255 | MockRead(SYNCHRONOUS, OK), |
| 16256 | }; |
| 16257 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16258 | http_writes, arraysize(http_writes)); |
| 16259 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16260 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16262 | |
| 16263 | // Start the SSL request. |
| 16264 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16265 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16266 | ASSERT_EQ(ERR_IO_PENDING, |
| 16267 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16268 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16269 | |
| 16270 | // Start the HTTP request. Pool should stall. |
| 16271 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16272 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16273 | ASSERT_EQ(ERR_IO_PENDING, |
| 16274 | http_trans.Start(&http_request, http_callback.callback(), |
| 16275 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16276 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16277 | |
| 16278 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16279 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16280 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16281 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16282 | EXPECT_EQ("hello world", response_data); |
| 16283 | |
| 16284 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16285 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16286 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16287 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16288 | |
| 16289 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16290 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16291 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16292 | EXPECT_EQ("falafel", response_data); |
| 16293 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16294 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16295 | } |
| 16296 | |
| 16297 | // Tests that when a SSL connection is established but there's no corresponding |
| 16298 | // request that needs it, the new socket is closed if the transport socket pool |
| 16299 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16300 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16301 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16302 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16303 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16304 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16305 | |
| 16306 | // Set up an ssl request. |
| 16307 | |
| 16308 | HttpRequestInfo ssl_request; |
| 16309 | ssl_request.method = "GET"; |
| 16310 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 16311 | |
| 16312 | // No data will be sent on the SSL socket. |
| 16313 | StaticSocketDataProvider ssl_data; |
| 16314 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16315 | |
| 16316 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16318 | |
| 16319 | // Set up HTTP request. |
| 16320 | |
| 16321 | HttpRequestInfo http_request; |
| 16322 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16323 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16324 | |
| 16325 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16326 | MockWrite( |
| 16327 | "GET / HTTP/1.1\r\n" |
| 16328 | "Host: www.example.org\r\n" |
| 16329 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16330 | }; |
| 16331 | MockRead http_reads[] = { |
| 16332 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16333 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16334 | MockRead("falafel"), |
| 16335 | MockRead(SYNCHRONOUS, OK), |
| 16336 | }; |
| 16337 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16338 | http_writes, arraysize(http_writes)); |
| 16339 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16342 | |
| 16343 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16344 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16345 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16346 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16347 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16348 | |
| 16349 | // Start the HTTP request. Pool should stall. |
| 16350 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16351 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16352 | ASSERT_EQ(ERR_IO_PENDING, |
| 16353 | http_trans.Start(&http_request, http_callback.callback(), |
| 16354 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16355 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16356 | |
| 16357 | // The SSL connection will automatically be closed once the connection is |
| 16358 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16359 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16360 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16361 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16362 | EXPECT_EQ("falafel", response_data); |
| 16363 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16364 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16365 | } |
| 16366 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16367 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16368 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16369 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16370 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16371 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16372 | |
| 16373 | HttpRequestInfo request; |
| 16374 | request.method = "POST"; |
| 16375 | request.url = GURL("http://www.foo.com/"); |
| 16376 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16380 | // Send headers successfully, but get an error while sending the body. |
| 16381 | MockWrite data_writes[] = { |
| 16382 | MockWrite("POST / HTTP/1.1\r\n" |
| 16383 | "Host: www.foo.com\r\n" |
| 16384 | "Connection: keep-alive\r\n" |
| 16385 | "Content-Length: 3\r\n\r\n"), |
| 16386 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16387 | }; |
| 16388 | |
| 16389 | MockRead data_reads[] = { |
| 16390 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16391 | MockRead("hello world"), |
| 16392 | MockRead(SYNCHRONOUS, OK), |
| 16393 | }; |
| 16394 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16395 | arraysize(data_writes)); |
| 16396 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16397 | |
| 16398 | TestCompletionCallback callback; |
| 16399 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16400 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16402 | |
| 16403 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16404 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16406 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16407 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16408 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16409 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16410 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16411 | |
| 16412 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16413 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16415 | EXPECT_EQ("hello world", response_data); |
| 16416 | } |
| 16417 | |
| 16418 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16419 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16420 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16421 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16423 | MockWrite data_writes[] = { |
| 16424 | MockWrite("GET / HTTP/1.1\r\n" |
| 16425 | "Host: www.foo.com\r\n" |
| 16426 | "Connection: keep-alive\r\n\r\n"), |
| 16427 | MockWrite("POST / HTTP/1.1\r\n" |
| 16428 | "Host: www.foo.com\r\n" |
| 16429 | "Connection: keep-alive\r\n" |
| 16430 | "Content-Length: 3\r\n\r\n"), |
| 16431 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16432 | }; |
| 16433 | |
| 16434 | MockRead data_reads[] = { |
| 16435 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16436 | "Content-Length: 14\r\n\r\n"), |
| 16437 | MockRead("first response"), |
| 16438 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16439 | "Content-Length: 15\r\n\r\n"), |
| 16440 | MockRead("second response"), |
| 16441 | MockRead(SYNCHRONOUS, OK), |
| 16442 | }; |
| 16443 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16444 | arraysize(data_writes)); |
| 16445 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16446 | |
| 16447 | TestCompletionCallback callback; |
| 16448 | HttpRequestInfo request1; |
| 16449 | request1.method = "GET"; |
| 16450 | request1.url = GURL("http://www.foo.com/"); |
| 16451 | request1.load_flags = 0; |
| 16452 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16453 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16454 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16455 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16457 | |
| 16458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16460 | |
| 16461 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16462 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16463 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16464 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16465 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16466 | |
| 16467 | std::string response_data1; |
| 16468 | rv = ReadTransaction(trans1.get(), &response_data1); |
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 | EXPECT_EQ("first response", response_data1); |
| 16471 | // Delete the transaction to release the socket back into the socket pool. |
| 16472 | trans1.reset(); |
| 16473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16474 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16475 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16476 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16477 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16478 | |
| 16479 | HttpRequestInfo request2; |
| 16480 | request2.method = "POST"; |
| 16481 | request2.url = GURL("http://www.foo.com/"); |
| 16482 | request2.upload_data_stream = &upload_data_stream; |
| 16483 | request2.load_flags = 0; |
| 16484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16485 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16486 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16488 | |
| 16489 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16492 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16493 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16494 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16495 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16496 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16497 | |
| 16498 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16499 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16501 | EXPECT_EQ("second response", response_data2); |
| 16502 | } |
| 16503 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16504 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16505 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16506 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16507 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16508 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16509 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16510 | |
| 16511 | HttpRequestInfo request; |
| 16512 | request.method = "POST"; |
| 16513 | request.url = GURL("http://www.foo.com/"); |
| 16514 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16515 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16516 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16518 | // Send headers successfully, but get an error while sending the body. |
| 16519 | MockWrite data_writes[] = { |
| 16520 | MockWrite("POST / HTTP/1.1\r\n" |
| 16521 | "Host: www.foo.com\r\n" |
| 16522 | "Connection: keep-alive\r\n" |
| 16523 | "Content-Length: 3\r\n\r\n" |
| 16524 | "fo"), |
| 16525 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16526 | }; |
| 16527 | |
| 16528 | MockRead data_reads[] = { |
| 16529 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16530 | MockRead("hello world"), |
| 16531 | MockRead(SYNCHRONOUS, OK), |
| 16532 | }; |
| 16533 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16534 | arraysize(data_writes)); |
| 16535 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16536 | |
| 16537 | TestCompletionCallback callback; |
| 16538 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16539 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16541 | |
| 16542 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16545 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16546 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16547 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16548 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16549 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16550 | |
| 16551 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16552 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16553 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16554 | EXPECT_EQ("hello world", response_data); |
| 16555 | } |
| 16556 | |
| 16557 | // This tests the more common case than the previous test, where headers and |
| 16558 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16559 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16560 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16561 | |
| 16562 | HttpRequestInfo request; |
| 16563 | request.method = "POST"; |
| 16564 | request.url = GURL("http://www.foo.com/"); |
| 16565 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16569 | // Send headers successfully, but get an error while sending the body. |
| 16570 | MockWrite data_writes[] = { |
| 16571 | MockWrite("POST / HTTP/1.1\r\n" |
| 16572 | "Host: www.foo.com\r\n" |
| 16573 | "Connection: keep-alive\r\n" |
| 16574 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16575 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16576 | }; |
| 16577 | |
| 16578 | MockRead data_reads[] = { |
| 16579 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16580 | MockRead("hello world"), |
| 16581 | MockRead(SYNCHRONOUS, OK), |
| 16582 | }; |
| 16583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16584 | arraysize(data_writes)); |
| 16585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16586 | |
| 16587 | TestCompletionCallback callback; |
| 16588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16591 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16592 | // they can't be merged with the body in a single send. Not currently |
| 16593 | // necessary since a chunked body is never merged with headers, but this makes |
| 16594 | // the test more future proof. |
| 16595 | base::RunLoop().RunUntilIdle(); |
| 16596 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16597 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16598 | |
| 16599 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16600 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16602 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16603 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16604 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16605 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16606 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16607 | |
| 16608 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16609 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16610 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16611 | EXPECT_EQ("hello world", response_data); |
| 16612 | } |
| 16613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16614 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16615 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16616 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16617 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16618 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16619 | |
| 16620 | HttpRequestInfo request; |
| 16621 | request.method = "POST"; |
| 16622 | request.url = GURL("http://www.foo.com/"); |
| 16623 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16627 | |
| 16628 | MockWrite data_writes[] = { |
| 16629 | MockWrite("POST / HTTP/1.1\r\n" |
| 16630 | "Host: www.foo.com\r\n" |
| 16631 | "Connection: keep-alive\r\n" |
| 16632 | "Content-Length: 3\r\n\r\n"), |
| 16633 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16634 | }; |
| 16635 | |
| 16636 | MockRead data_reads[] = { |
| 16637 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16638 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16639 | MockRead("hello world"), |
| 16640 | MockRead(SYNCHRONOUS, OK), |
| 16641 | }; |
| 16642 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16643 | arraysize(data_writes)); |
| 16644 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16645 | |
| 16646 | TestCompletionCallback callback; |
| 16647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16650 | |
| 16651 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16652 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16655 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16656 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16657 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16658 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16659 | |
| 16660 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16661 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16662 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16663 | EXPECT_EQ("hello world", response_data); |
| 16664 | } |
| 16665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16666 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16667 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16668 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16669 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16670 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16671 | |
| 16672 | HttpRequestInfo request; |
| 16673 | request.method = "POST"; |
| 16674 | request.url = GURL("http://www.foo.com/"); |
| 16675 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16679 | // Send headers successfully, but get an error while sending the body. |
| 16680 | MockWrite data_writes[] = { |
| 16681 | MockWrite("POST / HTTP/1.1\r\n" |
| 16682 | "Host: www.foo.com\r\n" |
| 16683 | "Connection: keep-alive\r\n" |
| 16684 | "Content-Length: 3\r\n\r\n"), |
| 16685 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16686 | }; |
| 16687 | |
| 16688 | MockRead data_reads[] = { |
| 16689 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16690 | MockRead("hello world"), |
| 16691 | MockRead(SYNCHRONOUS, OK), |
| 16692 | }; |
| 16693 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16694 | arraysize(data_writes)); |
| 16695 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16696 | |
| 16697 | TestCompletionCallback callback; |
| 16698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16699 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16700 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16701 | |
| 16702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16703 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16704 | } |
| 16705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16706 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16707 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16708 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16709 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16710 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16711 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16712 | |
| 16713 | HttpRequestInfo request; |
| 16714 | request.method = "POST"; |
| 16715 | request.url = GURL("http://www.foo.com/"); |
| 16716 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16720 | // Send headers successfully, but get an error while sending the body. |
| 16721 | MockWrite data_writes[] = { |
| 16722 | MockWrite("POST / HTTP/1.1\r\n" |
| 16723 | "Host: www.foo.com\r\n" |
| 16724 | "Connection: keep-alive\r\n" |
| 16725 | "Content-Length: 3\r\n\r\n"), |
| 16726 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16727 | }; |
| 16728 | |
| 16729 | MockRead data_reads[] = { |
| 16730 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16731 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16732 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16733 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16734 | MockRead(SYNCHRONOUS, OK), |
| 16735 | }; |
| 16736 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16737 | arraysize(data_writes)); |
| 16738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16739 | |
| 16740 | TestCompletionCallback callback; |
| 16741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16742 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16744 | |
| 16745 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16746 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16747 | } |
| 16748 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16749 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16750 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16751 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16752 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16753 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16754 | |
| 16755 | HttpRequestInfo request; |
| 16756 | request.method = "POST"; |
| 16757 | request.url = GURL("http://www.foo.com/"); |
| 16758 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16761 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16762 | // Send headers successfully, but get an error while sending the body. |
| 16763 | MockWrite data_writes[] = { |
| 16764 | MockWrite("POST / HTTP/1.1\r\n" |
| 16765 | "Host: www.foo.com\r\n" |
| 16766 | "Connection: keep-alive\r\n" |
| 16767 | "Content-Length: 3\r\n\r\n"), |
| 16768 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16769 | }; |
| 16770 | |
| 16771 | MockRead data_reads[] = { |
| 16772 | MockRead("HTTP 0.9 rocks!"), |
| 16773 | MockRead(SYNCHRONOUS, OK), |
| 16774 | }; |
| 16775 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16776 | arraysize(data_writes)); |
| 16777 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16778 | |
| 16779 | TestCompletionCallback callback; |
| 16780 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16781 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16783 | |
| 16784 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16785 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16786 | } |
| 16787 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16788 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16789 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16790 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16791 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16792 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16793 | |
| 16794 | HttpRequestInfo request; |
| 16795 | request.method = "POST"; |
| 16796 | request.url = GURL("http://www.foo.com/"); |
| 16797 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16801 | // Send headers successfully, but get an error while sending the body. |
| 16802 | MockWrite data_writes[] = { |
| 16803 | MockWrite("POST / HTTP/1.1\r\n" |
| 16804 | "Host: www.foo.com\r\n" |
| 16805 | "Connection: keep-alive\r\n" |
| 16806 | "Content-Length: 3\r\n\r\n"), |
| 16807 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16808 | }; |
| 16809 | |
| 16810 | MockRead data_reads[] = { |
| 16811 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16812 | MockRead(SYNCHRONOUS, OK), |
| 16813 | }; |
| 16814 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16815 | arraysize(data_writes)); |
| 16816 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16817 | |
| 16818 | TestCompletionCallback callback; |
| 16819 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16820 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16822 | |
| 16823 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16824 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16825 | } |
| 16826 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16827 | // Verify that proxy headers are not sent to the destination server when |
| 16828 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16829 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16830 | HttpRequestInfo request; |
| 16831 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16832 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16833 | AddWebSocketHeaders(&request.extra_headers); |
| 16834 | |
| 16835 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16836 | session_deps_.proxy_service = |
| 16837 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16838 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16840 | |
| 16841 | // Since a proxy is configured, try to establish a tunnel. |
| 16842 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16843 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16844 | "Host: www.example.org:443\r\n" |
| 16845 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16846 | |
| 16847 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16848 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16849 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16850 | "Host: www.example.org:443\r\n" |
| 16851 | "Proxy-Connection: keep-alive\r\n" |
| 16852 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16853 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16854 | MockWrite("GET / HTTP/1.1\r\n" |
| 16855 | "Host: www.example.org\r\n" |
| 16856 | "Connection: Upgrade\r\n" |
| 16857 | "Upgrade: websocket\r\n" |
| 16858 | "Origin: http://www.example.org\r\n" |
| 16859 | "Sec-WebSocket-Version: 13\r\n" |
| 16860 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16861 | }; |
| 16862 | |
| 16863 | // The proxy responds to the connect with a 407, using a persistent |
| 16864 | // connection. |
| 16865 | MockRead data_reads[] = { |
| 16866 | // No credentials. |
| 16867 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16868 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16869 | MockRead("Content-Length: 0\r\n"), |
| 16870 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16871 | |
| 16872 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16873 | |
| 16874 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16875 | MockRead("Upgrade: websocket\r\n"), |
| 16876 | MockRead("Connection: Upgrade\r\n"), |
| 16877 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16878 | }; |
| 16879 | |
| 16880 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16881 | arraysize(data_writes)); |
| 16882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16883 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16885 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16886 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16887 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16888 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16889 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16890 | &websocket_stream_create_helper); |
| 16891 | |
| 16892 | { |
| 16893 | TestCompletionCallback callback; |
| 16894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16895 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16897 | |
| 16898 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16899 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16900 | } |
| 16901 | |
| 16902 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16903 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16904 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16905 | EXPECT_EQ(407, response->headers->response_code()); |
| 16906 | |
| 16907 | { |
| 16908 | TestCompletionCallback callback; |
| 16909 | |
| 16910 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16911 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16913 | |
| 16914 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16915 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16916 | } |
| 16917 | |
| 16918 | response = trans->GetResponseInfo(); |
| 16919 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16920 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16921 | |
| 16922 | EXPECT_EQ(101, response->headers->response_code()); |
| 16923 | |
| 16924 | trans.reset(); |
| 16925 | session->CloseAllConnections(); |
| 16926 | } |
| 16927 | |
| 16928 | // Verify that proxy headers are not sent to the destination server when |
| 16929 | // establishing a tunnel for an insecure WebSocket connection. |
| 16930 | // This requires the authentication info to be injected into the auth cache |
| 16931 | // due to crbug.com/395064 |
| 16932 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16933 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16934 | HttpRequestInfo request; |
| 16935 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16936 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16937 | AddWebSocketHeaders(&request.extra_headers); |
| 16938 | |
| 16939 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16940 | session_deps_.proxy_service = |
| 16941 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16942 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16944 | |
| 16945 | MockWrite data_writes[] = { |
| 16946 | // Try to establish a tunnel for the WebSocket connection, with |
| 16947 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16948 | // they cannot and will not use the same TCP/IP connection as the |
| 16949 | // preflight HTTP request. |
| 16950 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16951 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16952 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16953 | "Proxy-Connection: keep-alive\r\n" |
| 16954 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16955 | |
| 16956 | MockWrite( |
| 16957 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16958 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16959 | "Connection: Upgrade\r\n" |
| 16960 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16961 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16962 | "Sec-WebSocket-Version: 13\r\n" |
| 16963 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16964 | }; |
| 16965 | |
| 16966 | MockRead data_reads[] = { |
| 16967 | // HTTP CONNECT with credentials. |
| 16968 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16969 | |
| 16970 | // WebSocket connection established inside tunnel. |
| 16971 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16972 | MockRead("Upgrade: websocket\r\n"), |
| 16973 | MockRead("Connection: Upgrade\r\n"), |
| 16974 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16975 | }; |
| 16976 | |
| 16977 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16978 | arraysize(data_writes)); |
| 16979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16980 | |
| 16981 | session->http_auth_cache()->Add( |
| 16982 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16983 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16984 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16985 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16986 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16987 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16988 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16989 | &websocket_stream_create_helper); |
| 16990 | |
| 16991 | TestCompletionCallback callback; |
| 16992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16993 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16995 | |
| 16996 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16997 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16998 | |
| 16999 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17000 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17001 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17002 | |
| 17003 | EXPECT_EQ(101, response->headers->response_code()); |
| 17004 | |
| 17005 | trans.reset(); |
| 17006 | session->CloseAllConnections(); |
| 17007 | } |
| 17008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17009 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17010 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17011 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17012 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17013 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17014 | |
| 17015 | HttpRequestInfo request; |
| 17016 | request.method = "POST"; |
| 17017 | request.url = GURL("http://www.foo.com/"); |
| 17018 | request.upload_data_stream = &upload_data_stream; |
| 17019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17022 | MockWrite data_writes[] = { |
| 17023 | MockWrite("POST / HTTP/1.1\r\n" |
| 17024 | "Host: www.foo.com\r\n" |
| 17025 | "Connection: keep-alive\r\n" |
| 17026 | "Content-Length: 3\r\n\r\n"), |
| 17027 | MockWrite("foo"), |
| 17028 | }; |
| 17029 | |
| 17030 | MockRead data_reads[] = { |
| 17031 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17032 | MockRead(SYNCHRONOUS, OK), |
| 17033 | }; |
| 17034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17035 | arraysize(data_writes)); |
| 17036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17037 | |
| 17038 | TestCompletionCallback callback; |
| 17039 | |
| 17040 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17041 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17042 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17043 | |
| 17044 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17045 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17046 | |
| 17047 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17048 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17049 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17050 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17051 | } |
| 17052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17053 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17054 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17055 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17056 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17057 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17058 | |
| 17059 | HttpRequestInfo request; |
| 17060 | request.method = "POST"; |
| 17061 | request.url = GURL("http://www.foo.com/"); |
| 17062 | request.upload_data_stream = &upload_data_stream; |
| 17063 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17066 | MockWrite data_writes[] = { |
| 17067 | MockWrite("POST / HTTP/1.1\r\n" |
| 17068 | "Host: www.foo.com\r\n" |
| 17069 | "Connection: keep-alive\r\n" |
| 17070 | "Content-Length: 3\r\n\r\n"), |
| 17071 | MockWrite("foo"), |
| 17072 | }; |
| 17073 | |
| 17074 | MockRead data_reads[] = { |
| 17075 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17076 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17077 | MockRead(SYNCHRONOUS, OK), |
| 17078 | }; |
| 17079 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17080 | arraysize(data_writes)); |
| 17081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17082 | |
| 17083 | TestCompletionCallback callback; |
| 17084 | |
| 17085 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17086 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17087 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17088 | |
| 17089 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17090 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17091 | |
| 17092 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17093 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17094 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17095 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17096 | } |
| 17097 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17098 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17099 | ChunkedUploadDataStream upload_data_stream(0); |
| 17100 | |
| 17101 | HttpRequestInfo request; |
| 17102 | request.method = "POST"; |
| 17103 | request.url = GURL("http://www.foo.com/"); |
| 17104 | request.upload_data_stream = &upload_data_stream; |
| 17105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17107 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17108 | // Send headers successfully, but get an error while sending the body. |
| 17109 | MockWrite data_writes[] = { |
| 17110 | MockWrite("POST / HTTP/1.1\r\n" |
| 17111 | "Host: www.foo.com\r\n" |
| 17112 | "Connection: keep-alive\r\n" |
| 17113 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17114 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17115 | }; |
| 17116 | |
| 17117 | MockRead data_reads[] = { |
| 17118 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17119 | MockRead(SYNCHRONOUS, OK), |
| 17120 | }; |
| 17121 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17122 | arraysize(data_writes)); |
| 17123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17124 | |
| 17125 | TestCompletionCallback callback; |
| 17126 | |
| 17127 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17128 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17129 | |
| 17130 | base::RunLoop().RunUntilIdle(); |
| 17131 | upload_data_stream.AppendData("f", 1, false); |
| 17132 | |
| 17133 | base::RunLoop().RunUntilIdle(); |
| 17134 | upload_data_stream.AppendData("oo", 2, true); |
| 17135 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17136 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17137 | |
| 17138 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17139 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17140 | |
| 17141 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17142 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17143 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17144 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17145 | } |
| 17146 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17147 | // Confirm that transactions whose throttle is created in (and stays in) |
| 17148 | // the unthrottled state are not blocked. |
| 17149 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 17150 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17151 | std::unique_ptr<HttpNetworkSession> session( |
| 17152 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17153 | |
| 17154 | // Send a simple request and make sure it goes through. |
| 17155 | HttpRequestInfo request; |
| 17156 | request.method = "GET"; |
| 17157 | request.url = GURL("http://www.example.org/"); |
| 17158 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17159 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17160 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17161 | |
| 17162 | MockWrite data_writes[] = { |
| 17163 | MockWrite("GET / HTTP/1.1\r\n" |
| 17164 | "Host: www.example.org\r\n" |
| 17165 | "Connection: keep-alive\r\n\r\n"), |
| 17166 | }; |
| 17167 | MockRead data_reads[] = { |
| 17168 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17169 | MockRead(SYNCHRONOUS, OK), |
| 17170 | }; |
| 17171 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17172 | arraysize(data_writes)); |
| 17173 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17174 | |
| 17175 | TestCompletionCallback callback; |
| 17176 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17177 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17178 | } |
| 17179 | |
| 17180 | // Confirm requests can be blocked by a throttler, and are resumed |
| 17181 | // when the throttle is unblocked. |
| 17182 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 17183 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17184 | std::unique_ptr<HttpNetworkSession> session( |
| 17185 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17186 | |
| 17187 | // Send a simple request and make sure it goes through. |
| 17188 | HttpRequestInfo request; |
| 17189 | request.method = "GET"; |
| 17190 | request.url = GURL("http://www.example.org/"); |
| 17191 | |
| 17192 | MockWrite data_writes[] = { |
| 17193 | MockWrite("GET / HTTP/1.1\r\n" |
| 17194 | "Host: www.example.org\r\n" |
| 17195 | "Connection: keep-alive\r\n\r\n"), |
| 17196 | }; |
| 17197 | MockRead data_reads[] = { |
| 17198 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17199 | MockRead(SYNCHRONOUS, OK), |
| 17200 | }; |
| 17201 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17202 | arraysize(data_writes)); |
| 17203 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17204 | |
| 17205 | // Start a request that will be throttled at start; confirm it |
| 17206 | // doesn't complete. |
| 17207 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17208 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17209 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17210 | |
| 17211 | TestCompletionCallback callback; |
| 17212 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17213 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17214 | |
| 17215 | base::RunLoop().RunUntilIdle(); |
| 17216 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17217 | EXPECT_FALSE(callback.have_result()); |
| 17218 | |
| 17219 | // Confirm the request goes on to complete when unthrottled. |
| 17220 | throttler->UnthrottleAllRequests(); |
| 17221 | base::RunLoop().RunUntilIdle(); |
| 17222 | ASSERT_TRUE(callback.have_result()); |
| 17223 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17224 | } |
| 17225 | |
| 17226 | // Destroy a request while it's throttled. |
| 17227 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 17228 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17229 | std::unique_ptr<HttpNetworkSession> session( |
| 17230 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17231 | |
| 17232 | // Send a simple request and make sure it goes through. |
| 17233 | HttpRequestInfo request; |
| 17234 | request.method = "GET"; |
| 17235 | request.url = GURL("http://www.example.org/"); |
| 17236 | |
| 17237 | MockWrite data_writes[] = { |
| 17238 | MockWrite("GET / HTTP/1.1\r\n" |
| 17239 | "Host: www.example.org\r\n" |
| 17240 | "Connection: keep-alive\r\n\r\n"), |
| 17241 | }; |
| 17242 | MockRead data_reads[] = { |
| 17243 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17244 | MockRead(SYNCHRONOUS, OK), |
| 17245 | }; |
| 17246 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17247 | arraysize(data_writes)); |
| 17248 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17249 | |
| 17250 | // Start a request that will be throttled at start; confirm it |
| 17251 | // doesn't complete. |
| 17252 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17253 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17254 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17255 | |
| 17256 | TestCompletionCallback callback; |
| 17257 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17258 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17259 | |
| 17260 | base::RunLoop().RunUntilIdle(); |
| 17261 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17262 | EXPECT_FALSE(callback.have_result()); |
| 17263 | |
| 17264 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 17265 | trans.reset(); |
| 17266 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 17267 | } |
| 17268 | |
| 17269 | // Confirm the throttler receives SetPriority calls. |
| 17270 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 17271 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17272 | std::unique_ptr<HttpNetworkSession> session( |
| 17273 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17274 | |
| 17275 | // Send a simple request and make sure it goes through. |
| 17276 | HttpRequestInfo request; |
| 17277 | request.method = "GET"; |
| 17278 | request.url = GURL("http://www.example.org/"); |
| 17279 | |
| 17280 | MockWrite data_writes[] = { |
| 17281 | MockWrite("GET / HTTP/1.1\r\n" |
| 17282 | "Host: www.example.org\r\n" |
| 17283 | "Connection: keep-alive\r\n\r\n"), |
| 17284 | }; |
| 17285 | MockRead data_reads[] = { |
| 17286 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17287 | MockRead(SYNCHRONOUS, OK), |
| 17288 | }; |
| 17289 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17290 | arraysize(data_writes)); |
| 17291 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17292 | |
| 17293 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17294 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17295 | // Start the transaction to associate a throttle with it. |
| 17296 | TestCompletionCallback callback; |
| 17297 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17298 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17299 | |
| 17300 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 17301 | trans->SetPriority(LOW); |
| 17302 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 17303 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 17304 | |
| 17305 | throttler->UnthrottleAllRequests(); |
| 17306 | base::RunLoop().RunUntilIdle(); |
| 17307 | ASSERT_TRUE(callback.have_result()); |
| 17308 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17309 | } |
| 17310 | |
| 17311 | // Confirm that unthrottling from a SetPriority call by the |
| 17312 | // throttler works properly. |
| 17313 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 17314 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17315 | std::unique_ptr<HttpNetworkSession> session( |
| 17316 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17317 | |
| 17318 | // Send a simple request and make sure it goes through. |
| 17319 | HttpRequestInfo request; |
| 17320 | request.method = "GET"; |
| 17321 | request.url = GURL("http://www.example.org/"); |
| 17322 | |
| 17323 | MockWrite data_writes[] = { |
| 17324 | MockWrite("GET / HTTP/1.1\r\n" |
| 17325 | "Host: www.example.org\r\n" |
| 17326 | "Connection: keep-alive\r\n\r\n"), |
| 17327 | }; |
| 17328 | MockRead data_reads[] = { |
| 17329 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17330 | MockRead(SYNCHRONOUS, OK), |
| 17331 | }; |
| 17332 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17333 | arraysize(data_writes)); |
| 17334 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17335 | |
| 17336 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17337 | data_writes, arraysize(data_writes)); |
| 17338 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17339 | |
| 17340 | // Start a request that will be throttled at start; confirm it |
| 17341 | // doesn't complete. |
| 17342 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17343 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17345 | |
| 17346 | TestCompletionCallback callback; |
| 17347 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17348 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17349 | |
| 17350 | base::RunLoop().RunUntilIdle(); |
| 17351 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17352 | EXPECT_FALSE(callback.have_result()); |
| 17353 | |
| 17354 | // Create a new request, call SetPriority on it to unthrottle, |
| 17355 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17356 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17357 | throttler->set_priority_change_closure( |
| 17358 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17359 | base::Unretained(throttler))); |
| 17360 | |
| 17361 | // Start the transaction to associate a throttle with it. |
| 17362 | TestCompletionCallback callback1; |
| 17363 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17364 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17365 | |
| 17366 | trans1->SetPriority(IDLE); |
| 17367 | |
| 17368 | base::RunLoop().RunUntilIdle(); |
| 17369 | ASSERT_TRUE(callback.have_result()); |
| 17370 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17371 | ASSERT_TRUE(callback1.have_result()); |
| 17372 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17373 | } |
| 17374 | |
| 17375 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17376 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17377 | |
| 17378 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17379 | // throttler works properly. |
| 17380 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17381 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17382 | std::unique_ptr<HttpNetworkSession> session( |
| 17383 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17384 | |
| 17385 | // Send a simple request and make sure it goes through. |
| 17386 | HttpRequestInfo request; |
| 17387 | request.method = "GET"; |
| 17388 | request.url = GURL("http://www.example.org/"); |
| 17389 | |
| 17390 | MockWrite data_writes[] = { |
| 17391 | MockWrite("GET / HTTP/1.1\r\n" |
| 17392 | "Host: www.example.org\r\n" |
| 17393 | "Connection: keep-alive\r\n\r\n"), |
| 17394 | }; |
| 17395 | MockRead data_reads[] = { |
| 17396 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17397 | MockRead(SYNCHRONOUS, OK), |
| 17398 | }; |
| 17399 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17400 | arraysize(data_writes)); |
| 17401 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17402 | |
| 17403 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17404 | data_writes, arraysize(data_writes)); |
| 17405 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17406 | |
| 17407 | // Start a request that will be throttled at start; confirm it |
| 17408 | // doesn't complete. |
| 17409 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17410 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17411 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17412 | |
| 17413 | TestCompletionCallback callback; |
| 17414 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17415 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17416 | |
| 17417 | base::RunLoop().RunUntilIdle(); |
| 17418 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17419 | EXPECT_FALSE(callback.have_result()); |
| 17420 | |
| 17421 | // Arrange for the set priority call on the above transaction to delete |
| 17422 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17423 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17424 | throttler->set_priority_change_closure( |
| 17425 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17426 | |
| 17427 | // Call it and check results (partially a "doesn't crash" test). |
| 17428 | trans_ptr->SetPriority(IDLE); |
| 17429 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17430 | |
| 17431 | base::RunLoop().RunUntilIdle(); |
| 17432 | ASSERT_FALSE(callback.have_result()); |
| 17433 | } |
| 17434 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17435 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17436 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17437 | const std::string https_url = "https://www.example.com"; |
| 17438 | HttpRequestInfo request; |
| 17439 | request.url = GURL(https_url); |
| 17440 | request.method = "GET"; |
| 17441 | |
| 17442 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 17443 | ssl.ssl_info.token_binding_negotiated = true; |
| 17444 | ssl.ssl_info.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17445 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17447 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17448 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17449 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17450 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17451 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17452 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17454 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17455 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17457 | |
| 17458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17459 | TestCompletionCallback callback; |
| 17460 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17461 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17462 | |
| 17463 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17464 | |
| 17465 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17466 | HttpRequestHeaders headers; |
| 17467 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17468 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17469 | } |
| 17470 | #endif // !defined(OS_IOS) |
| 17471 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17472 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17473 | const std::string& accept_encoding, |
| 17474 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17475 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17476 | bool should_match) { |
| 17477 | HttpRequestInfo request; |
| 17478 | request.method = "GET"; |
| 17479 | request.url = GURL("http://www.foo.com/"); |
| 17480 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17481 | accept_encoding); |
| 17482 | |
| 17483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17484 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17485 | // Send headers successfully, but get an error while sending the body. |
| 17486 | MockWrite data_writes[] = { |
| 17487 | MockWrite("GET / HTTP/1.1\r\n" |
| 17488 | "Host: www.foo.com\r\n" |
| 17489 | "Connection: keep-alive\r\n" |
| 17490 | "Accept-Encoding: "), |
| 17491 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17492 | }; |
| 17493 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17494 | std::string response_code = "200 OK"; |
| 17495 | std::string extra; |
| 17496 | if (!location.empty()) { |
| 17497 | response_code = "301 Redirect\r\nLocation: "; |
| 17498 | response_code.append(location); |
| 17499 | } |
| 17500 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17501 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17502 | MockRead("HTTP/1.0 "), |
| 17503 | MockRead(response_code.data()), |
| 17504 | MockRead("\r\nContent-Encoding: "), |
| 17505 | MockRead(content_encoding.data()), |
| 17506 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17507 | MockRead(SYNCHRONOUS, OK), |
| 17508 | }; |
| 17509 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17510 | arraysize(data_writes)); |
| 17511 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17512 | |
| 17513 | TestCompletionCallback callback; |
| 17514 | |
| 17515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17517 | |
| 17518 | rv = callback.WaitForResult(); |
| 17519 | if (should_match) { |
| 17520 | EXPECT_THAT(rv, IsOk()); |
| 17521 | } else { |
| 17522 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17523 | } |
| 17524 | } |
| 17525 | |
| 17526 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17527 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17528 | } |
| 17529 | |
| 17530 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17531 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17532 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17533 | } |
| 17534 | |
| 17535 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17536 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17537 | "", false); |
| 17538 | } |
| 17539 | |
| 17540 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17541 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17542 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17543 | } |
| 17544 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17545 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17546 | ProxyConfig proxy_config; |
| 17547 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17548 | proxy_config.set_pac_mandatory(true); |
| 17549 | MockAsyncProxyResolver resolver; |
| 17550 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17551 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17552 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17553 | |
| 17554 | HttpRequestInfo request; |
| 17555 | request.method = "GET"; |
| 17556 | request.url = GURL("http://www.example.org/"); |
| 17557 | |
| 17558 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17560 | |
| 17561 | TestCompletionCallback callback; |
| 17562 | |
| 17563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17565 | EXPECT_THAT(callback.WaitForResult(), |
| 17566 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17567 | } |
| 17568 | |
| 17569 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17570 | ProxyConfig proxy_config; |
| 17571 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17572 | proxy_config.set_pac_mandatory(true); |
| 17573 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17574 | new MockAsyncProxyResolverFactory(false); |
| 17575 | MockAsyncProxyResolver resolver; |
| 17576 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17577 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17578 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17579 | HttpRequestInfo request; |
| 17580 | request.method = "GET"; |
| 17581 | request.url = GURL("http://www.example.org/"); |
| 17582 | |
| 17583 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17585 | |
| 17586 | TestCompletionCallback callback; |
| 17587 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17588 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17589 | |
| 17590 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17591 | ERR_FAILED, &resolver); |
| 17592 | EXPECT_THAT(callback.WaitForResult(), |
| 17593 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17594 | } |
| 17595 | |
| 17596 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17597 | session_deps_.proxy_service = |
| 17598 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17599 | session_deps_.enable_quic = false; |
| 17600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17601 | |
| 17602 | HttpRequestInfo request; |
| 17603 | request.method = "GET"; |
| 17604 | request.url = GURL("http://www.example.org/"); |
| 17605 | |
| 17606 | TestCompletionCallback callback; |
| 17607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17608 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17609 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17610 | |
| 17611 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17612 | } |
| 17613 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17614 | } // namespace net |